Author Topic: Some more python Problems  (Read 3705 times)

Is there any way to actually open up an executable file in python?
Ive looked online for loving ages and cannot find any help that will let me open up an execuatble file in python.

For example, Ive extracted some of my code from something simple that im writing:
Code: [Select]
if(choice == "Yes"):
    print("You chose Yes!")
    import time
    time.sleep (1.5)

Right after the time.sleep(1.5) I want some script that opens up a certain file from a certain directory.

Any help?


According to Google,
Code: [Select]
import os
os.startfile("C:\Documents and Settings\flow_model\flow.exe")

According to Google,
Code: [Select]
import os
os.startfile("C:\Documents and Settings\flow_model\flow.exe")

I think if the .exe file is in the same folder as your python script you don't need the full address.

import subprocess
process = subprocess.Popen(['flow.exe'])

I have a lot of python problems
it's just way too big to handl- oh

Solution: use a language that isn't stuffty as forget.

Solution: use a language that isn't stuffty as forget.

solid tip right here folks!

Solution: use a language that isn't stuffty as forget.
Was about to say it

Solution: use a language that isn't stuffty as forget.
such as english

I said this before. But you didn't see it - pm me for questions
Code: [Select]
import os.path
if os.path.exists("storage.txt"): # Check if the file "storage.txt" exists,

    a = open("storage.txt", "r+") # Open the file storage.txt, we know it exists because of the previous line ^
    hi = a.read(-1); # Change -1 to how many letters to read, -1 means everything

    print ("Hi, your username is - "+ str(hi)) # Show your name,
    changename = input("Would you like to change your name? - ").lower() # Ask to change name, .lower means make it all lowercase.
   
    if changename == "yes":
        username = input("Hello, enter in your name please - ")
        print ("Your username is now - "+ str(username))

        a = open("storage.txt", "w") # Open storage.txt for writing in the new username
        a.write(username) # Write the new username to the file.
        a.close() # Close the file.

    else:
        print ("Bye,")

else:
    username = input("Hello, enter in your name please - ") # Enter a string for the variable username
   
    a = open("Storage.txt", "w") # Check if a file with that name exists, if not creates the file. "W" means write
    a.write(username) # Puts in storage.txt what the variable username is.
    a.close() # Close file
   
    print ("Your username is -", username) # Print username

.. what is that post for? It has nothing with executing files.

I'll try to improve it for you anyway.

Code: [Select]
import os.path

if os.path.exists('storage.txt'):
    with open('storage.txt') as fp:
        name = fp.read()

    print('Hi, your username is {}.'.format(name))

    if input('Would you like to change your name? ').lower() in ('y', 'yes'):
        name = input('Hello, enter in your name please: ')
        print('Your username is now {}.'.format(name))

        with open('storage.txt', 'w') as fp:
            fp.write(name)
    else:
        print('Bye')
else:
    name = input('Hello, enter in your name please: ')

    with open('storage.txt', 'w') as fp:
        fp.write(name)

    print('Your username is {}.'.format(name))

.. what is that post for? It has nothing with executing files.

He had another post that he wanted to enter his name in and store it in a file for later use.
http://forum.blockland.us/index.php?topic=241360.msg6887415#msg6887415



By the way your's is complicated for a beginner to understand, mine is basically bare bones.

your's is complicated for a beginner to understand

How so?