Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 2nd, 2013, 12:31 AM
Paradox256 Paradox256 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 Paradox256 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 36 sec
Reputation Power: 0
How would I switch python files and run code from those files?

I'm fairly new to Python, with a fairly simple question. I'm trying to make a simple text game in Python, kinda like Zork, just to play around with the code. I wondered if I could do something like this and how:

there'd be a few files, like this:

start.py
otherfile.py

And this would happen. start.py would run fine and dandy, then when a certain thing happens (such as the player proceeds far enough for a certain variable to become True), it would run otherfile.py, instead of having all of the levels in one file. Is this possible? And how about a global variable shared between all files, such as the player's name, is that possible? I understand python syntax and understand enough to do some things within one file, but nothing like using multiple files.

Storing certain things like journal entries for when the player picks one up to read in its own file would be pretty neat too.

Sorry if I sound like a noob because I pretty much am, lol. Don't be harsh. This is also probably more work than i'm making it sound.

Reply With Quote
  #2  
Old January 2nd, 2013, 01:10 AM
Nyktos Nyktos is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 74 Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 2 h 22 m 37 sec
Reputation Power: 2
Probably your best bet would be:
1. In each file, place all the code you want to run into these functions.
2. Create a new file, say called main.py, which imports each of your other files.
3. From main.py, call the functions you defined in step 1.

Anything "global" can be placed in main.py and passed as an argument to your functions.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > How would I switch python files and run code from those files?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap