if 5 < 6: print ("error")
def adjust_to_correct_appdir(): import os, sys try: appdir = sys.argv #feel free to use __file__ if not appdir: raise ValueError appdir = os.path.abspath(os.path.dirname(sys.argv)) os.chdir(appdir) if not appdir in sys.path: sys.path.insert(0,appdir) except: #placeholder for feedback, adjust to your app. #remember to use only python and python standart libraries #not any resource or module into the appdir #a window in Tkinter can be adequate for apps without console #a simple print with a timeout can be enough for console apps print 'Please run from an OS console.' import time time.sleep(10) sys.exit(1) adjust_to_correct_appdir()
Add the code in any *.py thats directly runnable (ex. game.py , leveleditor.py ). It must be added near the begining of file, before importing any module living under the appdir, before opening any file with a filename relative to the appdir and before any pickle-unpickle operation.
Your app is started not from the appdir. As a result:
This can happen due to:
Way to go:
The second problem can only be solved if at the very beginning of the app the working directory is changed to appdir (os.chdir(appdir)).
appdir = os.path.abspath(os.path.dirname(sys.argv))
warning that sys.argv its usualy the command line used to start the app, but not guaranted. By example, if the entry point for the app lies in main.py, and someone start the app from the python interpreter console:
>>>execfile(r'\appedir\main.py') #in linux-mac '/appdir/main.py'
then sys.argv would be the empty string, at least in windows A most recent recipe ,the one that Im replacing, gets appdir as
appdir = os.path.abspath(os.path.dirname(__file__))
wich in the python console case will fail with NameError: __file__ is not defined
If you cannot resolve appdir, then the better is to give feedback to the user (print, a tkinter window, any that only uses python and standart libraries) and terminate the app.
... #in branch where sys.argv or __file__ tells nothing try: appdir=os.getcwd() f=file(os.path.join(appdir,'signature'),'rb') sig=file.read() f.close() if sig!='this is the myapp signature file - dont edit': # started from the interpreter but not in the appdir. raise # medium confirmation that the cwd is really the appdir except: #warn the user and quit
Personally, I woldnt bother.
Note that the python docs are unclear (or the info if burried somewhere) as the exact circumstances in wich sys.argv nor __file__ will not convey the info we want to extract. Also, from that blurriness, it is unclear if one is better than the other.
Try out that code box: where's my "<"?
if 1 <= x <= 2:
if 1 <= x <= 2:
Including an image
The Pygame draw package uses a crude, aliasing, algorithm to draw single pixel width circles. Thicker circles are composed of multiple single pixel width circles. There is not much overlapping of circles so, regrettably, it leaves holes.
Until Pygame incorporates a package like SDL_gfx (in pgreloaded already) with a filled-ellipse draw function programs will just have work around it. One solution, provided by Ian Mallett on the pygame-users, "is to draw a circle on a surface, then use pygame.draw.polygon() to clean off the parts you don't need. You can use colorkey-transparency as well to get 'cut-out' arcs." For arcs Ben Friman observed "that by making tiny adjustments to the arc angles, and re-drawing the arc, most of the holes would get covered up."
Wiki content parser output
Email bug reports and patches to the pygame-users mailing list
To submit a bug report to the mailing list:
To submit a patch to the mailing list:
Joining the mailing list to submit your patch or bug report will allow more people to look at your problem. If you do not want to join the mailing list please send your bug report or patch to renesd AT gmail DOT com.