ผมสร้างเงื่อนไขไว้ว่า

if i == 1:

ให้รันไฟล์ 1.py

else :

ให้รันไฟล์ 2.py

ได้รึเปล่าครับ
ผมจะใช้คำสั่งอะไรในการสั่งให้รันไฟล์ได้บ้างครับ

Hiring! บริษัทที่น่าสนใจ

Carmen Software company cover
Carmen Software
Hotel Financial Solutions
Next Innovation (Thailand) Co., Ltd. company cover
Next Innovation (Thailand) Co., Ltd.
We are web design with consulting & engineering services driven the future stronger and flexibility.
KKP Dime company cover
KKP Dime
KKP Dime บริษัทในเครือเกียรตินาคินภัทร
Kiatnakin Phatra Financial Group company cover
Kiatnakin Phatra Financial Group
Financial Service
Fastwork Technologies company cover
Fastwork Technologies
Fastwork.co เว็บไซต์ที่รวบรวม ฟรีแลนซ์ มืออาชีพจากหลากหลายสายงานไว้ในที่เดียวกัน
Thoughtworks Thailand company cover
Thoughtworks Thailand
Thoughtworks เป็นบริษัทที่ปรึกษาด้านเทคโนโยลีระดับโลกที่คว้า Great Place to Work 3 ปีซ้อน
Iron Software company cover
Iron Software
Iron Software is an American company providing a suite of .NET libraries by engineer for engineers.
CLEVERSE company cover
CLEVERSE
Cleverse is a Venture Builder. Our team builds several tech companies.
Nipa Cloud company cover
Nipa Cloud
#1 OpenStack cloud provider in Thailand with our own data center and software platform.
Bangmod Enterprise company cover
Bangmod Enterprise
The leader in Cloud Server and Hosting in Thailand.
CIMB THAI Bank company cover
CIMB THAI Bank
MOVING FORWARD WITH YOU - CIMB is the leading ASEAN Bank
Bangkok Bank company cover
Bangkok Bank
Bangkok Bank is one of Southeast Asia's largest regional banks, a market leader in business banking
MuvMi (Urban Mobility Tech Co.,Ltd.) company cover
MuvMi (Urban Mobility Tech Co.,Ltd.)
Shape the future of urban mobility towards affordable, clean, and safe solutions
T.N. Digital Solution Co., Ltd. company cover
T.N. Digital Solution Co., Ltd.
TNDS has been involving in every first move of banking’s major digital transformation.
KBTG - KASIKORN Business-Technology Group company cover
KBTG - KASIKORN Business-Technology Group
KBTG - "The Technology Company for Digital Business Innovation"
Siam Commercial Bank Public Company Limited company cover
Siam Commercial Bank Public Company Limited
"Let's start a brighter career future together"
Icon Framework co.,Ltd. company cover
Icon Framework co.,Ltd.
Global Standard Platform for Real Estate แพลตฟอร์มสำหรับธุรกิจอสังหาริมทรัพย์ครบวงจร มาตรฐานระดับโลก
REFINITIV company cover
REFINITIV
The Financial and Risk business of Thomson Reuters is now Refinitiv
H LAB company cover
H LAB
Re-engineering healthcare systems through intelligent platforms and system design.
The Gang Technology Co., Ltd. company cover
The Gang Technology Co., Ltd.
We're a Digital Agency that helps our customers transform their business into digital with ease.
LTMH company cover
LTMH
LTMH มุ่งเน้นการพัฒนาผลิตภัณฑ์ที่สามารถช่วยพันธมิตรของเราให้บรรลุเป้าหมาย
Seven Peaks company cover
Seven Peaks
We Drive Digital Transformation
Wisesight (Thailand) Co., Ltd. company cover
Wisesight (Thailand) Co., Ltd.
The Best Choice For Handling Social Media · High Expertise in Social Data · Most Advanced and Secure
MOLOG Tech company cover
MOLOG Tech
We are Modern Logistic Platform, Specialize in WMS, OMS and TMS.
Data Wow Co.,Ltd company cover
Data Wow Co.,Ltd
We enable our clients to realize increased productivity by solving their most complex issues by Data
LINE Company Thailand company cover
LINE Company Thailand
LINE, the world's hottest mobile messaging platform, offers free text and voice messaging + Call
LINE MAN Wongnai company cover
LINE MAN Wongnai
Join our journey to becoming No.1 food platform in Thailand

cwt Wed, 28/01/2009 - 08:36

google ด้วยคำว่า python execute command แล้วจะเจอคำตอบ

ถามจริงๆ ก่อนจะมาถามนี่เคยหาด้วย google ก่อนหรือเปล่า? (ไม่ได้ว่าอะไรแค่อยากรู้)

immortalt Wed, 28/01/2009 - 08:49

พี่ cwt คับ ถึงเขาจะไม่ได้เสิร์ช กูเกิล มา ก่อน แล้ว มา ทำ การ ถาม ใน บอร์ด ผม ก็ ว่า มัน เป็น สิทธิ์ ของ เขา นะ คับ

ไม่ควรมาพูด เหน็บแนม แบบนั้น มัน ทุเรศ อ่า คับ

บางคน เขา อาจ ใหม่ สำ หรับ การ เรียน รู้ ด้วย ตัว เอง ยัง ไม่ เซียน เขา ก็ ต้อง การ ถาม แล้ว ได้ คำ ตอบ เลย

นี่ ไม่ ตอบ แล้ว พูด กวน อีก ( แบบ ว่า ขอ บ่น หน่อย เห็น มา เยอะ มาก ใน หลายๆ เว็บ บอร์ด จะ มี คน แนวๆ นี้

อยู่ เยอะ ใคร ถาม อะไร ง่ายๆ มา ไล่ ไป เสิร์ช google ตลอด )

ตอบ คุณ zooshi ผมว่า ทำได้ คับ แม้จะไม่ เคยเขียน python มา ก่อน แต่ คิด ว่า ทำ ได้ ชัวร์ 100%

cwt Wed, 28/01/2009 - 19:38

In reply to by immortalt

google ด้วยคำว่า python execute command แล้วจะเจอคำตอบ

นี่คือคำตอบของผมไงครับ ถาม google ก็ได้คำตอบเลยเหมือนกันครับ และการถามใน webboard ก็ควรจะอนุมานได้อยู่แล้วว่าไม่ต้องการคำตอบทันที เพราะไม่รู้ว่าจะมีคนเข้ามาอ่านและมาตอบเมื่อไหร่ อีกอย่างถ้าผมตอบแบบนี้ คนที่อ่านก็จะพอจับคำถามโยงกับ keyword ที่ผมแนะให้ หลังจากนี้ก็จะสามารถใชั้ google ได้ด้วยตัวเอง

ผมไม่เห็นว่าการตอบแนวนี้จะทุเรศตรงไหนครับ

และกรุณาดูเวลาที่ผมตอบด้วย 8.36 คือเวลาที่ผมกำลังจะออกไปทำงาน ดังนั้นผมเข้ามาตอบให้สั้นๆ แบบนี้ ถ้าจังหวะนั้นคนถามเข้ามาอ่านและไปค้น google ตามที่บอกก็จะเจอคำตอบก่อนที่ผมจะมาถึงที่ทำงานซะอีก

Kurtumm Fri, 30/01/2009 - 20:29

In reply to by immortalt

ใครสั่งใครสอนให้เขียนภาษาไทยเว้นวรรคแบบนี้เหรอครับ

อาจารย์ภาษาไทยมาเห็นนี่ร้องไห้น้ำตาเป็นสายเลือดแน่

cwt Fri, 30/01/2009 - 23:43

In reply to by Kurtumm

ใจเย็นๆ ครับ มียุคนึงเราก็พยายามให้คนไทยเขียนแยกคำเหมือนกันนะ (น่าจะช่วงสงครามโลก) นัยว่าเอาใจฝรั่ง หนังสือเรียนภาษาไทยตอนประถม (สมัยผม) ก็เขียนแยกแบบนี้เหมือนกัน พอดีไปเจอ link นี้ ลองไปอ่านดูเค้าคุยกันเรื่องนี้ครับ

anu Wed, 28/01/2009 - 09:06

เค้าคงไม่รู้จะหาด้วย Keyword อะไร และอีกอย่างถึงหาเจอก็อาจจะอ่านไม่ออก ไม่อย่างนั้นคงหาเองแล้ว

ถามในนี้ ง่ายจะตาย ไม่ต้องหา แถมได้คำตอบเป็นภาษาไทยอีก..

a.py

import sys, subprocess

print "Hello this is a\n"

subprocess.call([sys.executable, "", "b.py"])

b.py

print "Hello this is b\n"

ทดลอง

python b.py

Hello this is b

python a.py

Hello this is a

Hello this is b

risc Wed, 28/01/2009 - 09:24

In reply to by anu

นั่งพิมพ์ตั้งนาน ท่าน anu มาตอบให้ละ เหอๆ ข้าน้อยขอคาราวะ หนึ่งจอก

แสวงหามิใช่เพราะรอคอย เชี่ยวชาญมิใช่เพราะโอกาส ชำนาญมิใช่เพราะโชคช่วย"ดังนี้แล้วลิขิตฟ้าหรือจะสู้มานะตน"chonlatee

risc Wed, 28/01/2009 - 09:22

ผมเคยเห็นใน codenone มีคน post หรือ reply ไว้นี้แหละ ใ้้ห้ python รันไฟล์อื่น

ตอบ zoozhi : ทำได้ครับให้ python excute ไฟล์อื่น

ผมหาให้แล้วครับ

If you want to run the whole other program, you can use the os.system()
function. Here's an example of how it might work:

import os
print "I will call this other program called hello.py"
os.system("python hello.py")

คัดลอกจาก

http://mail.python.org/pipermail/tutor/2002-September/017368.html

ขอแสดงความคิดเห็นในการ search หาข้อมูลก่อน : ผมเห็นด้วยคุณ cwt และ immortalt

เห็นด้วย immortalt : ผมก็เคยไปถามในบอร์ดบางบอร์ด บางคนก็ตอบบางคนก็ให้ไป search google จนผมไม่กล้าถามเลย ทั้งๆที่ผมก็หาแล้วนะใน google แต่ไม่เจอ อาจจะเกิดจากใช้ keyword ไม่ตรงอะไรประมาณนี้ ผมว่าถ้าไล่ให้ไป search google อย่างเดียว ไม่ต้องตั้งมาหรอกครับบอร์ดหรืออะไรที่คอยช่วยปัญหา ความคิดเห็นส่วนตัวนะครับ

เห็นด้วย cwt : คือบางคำถามเนี้ย search google ก็ไม่ได้ยากเย็นอะไรเลย อย่างเช่นคำถาม "ผมจะเริ่มเขียน python เริ่มยังไงดี" , "เขียน python ต้องทำยังไง" อันนี้ผมเเห็นด้วยครับ แต่บางคำถามก็ต้องนึกว่าจะใช้ keyword อะไรในการค้นหา อันนี้ตัวผมถือว่าอยากพอสมควร

กรณีของ จขกท นั้นถือว่าพอรับได้ แต่ถ้าหาใน google แล้วไม่เจอก็ควรจะบอกหน่อยว่า

"ผมหาใน google แล้วไม่เจอ ผมอาจจะใ้ช้คำไม่ถูกต้อง รบกวนด้วยครับ" ประมาณนี้

ท่านพี่ทั้งหลายในนี้จะได้รู้ว่า เราก็พยายามเหมือนกัน แต่ยังไม่ค้นพบแล้วรีบ หรือ เร่งด่วน ก็เลยถาม

แสวงหามิใช่เพราะรอคอย เชี่ยวชาญมิใช่เพราะโอกาส ชำนาญมิใช่เพราะโชคช่วย"ดังนี้แล้วลิขิตฟ้าหรือจะสู้มานะตน"chonlatee

zoozhi Wed, 28/01/2009 - 22:51

ขอบคุณทุกท่านนะครับสำหรับคำแน่ะนำ ผมลองทำดูแล้ว ก็ยังไม่ได้เลยครับ

ของคุณ anu ผมลองทำดูแล้วเริ่มจากลองโค้ดที่คุณให้ หลังจากรัน a.py คำตอบได้แต่ a ครับ b ไม่แสดงออกมาด้วย

ของคุณ risc ผมลองใช้ os.system แล้วนะครับแต่ผลลัพธ์แสดงที่หน้าจอดอส แล้วไม่ได้แสดงเป็นภาษาไทย ผมไม่แน่ใจว่าได้รึเปล่า

ของคุณ cwt ขอบคุณนะครับสำหรับ keyword ผมก็ลองตามที่คุณให้มา ก็เจอโค้ดบางแต่ยังรันไม่ได้นะครับ สงสัยคงจะใส่ค่าผิด

ผมรันผ่าน IDLE บน window นะครับ ไม่ทราบว่าจะเกี่ยวรึเปล่าที่รันไม่ได้

cwt Wed, 28/01/2009 - 23:21

In reply to by zoozhi

แบบนี้ค่อยน่าตอบหน่อยครับ คือได้ลองดูก่อน แล้วเจอปัญหา แล้วค่อยมาถามว่าปัญหาที่เจอคืออะไร


from subprocess import Popen,PIPE
p = Popen('/bin/ls', shell=True,stdout=PIPE,stderr=PIPE)
out = ''.join(p.stdout.readlines())
outerr = ''.join(p.stderr.readlines())

ลองทำแบบนี้ครับ parameter แรกของ Popen คือคำสั่งที่เราจะ execute

output จะอยู่ในตัวแปร out และ error จะอยู่ใน outerr

ตาม code นี้ถ้าสั่ง print out ก็จะเห็น output จากการ execute /bin/ls ครับ

ปล. code นี้ผมก็เอามาจาก link แรกที่ google เจอครับ แต่แก้นิดหน่อยให้ใช้บน python 2.5

risc Thu, 29/01/2009 - 09:45

In reply to by zoozhi

คงเกี่ยวกับการ encode ลองดูกระทู้นี้ครับ

http://www.blognone.com/node/10365

แสวงหามิใช่เพราะรอคอย เชี่ยวชาญมิใช่เพราะโอกาส ชำนาญมิใช่เพราะโชคช่วย"ดังนี้แล้วลิขิตฟ้าหรือจะสู้มานะตน"chonlatee

cwt Thu, 29/01/2009 - 15:09

In reply to by risc

ถ้า output ถูกส่งไปยัง command line (DOS) ของ windows ยังไงก็อ่านไม่ออกอยู่แล้วครับ เพราะว่า font ของ command line ใน windows ไม่มีภาษาไทย