Getting the Appdata Directory with Python and PEP?
I've heard that there is a library that allows you to get the appdata directory for a given OS, but I'd like to do it myself, as a learning experience. Is there a built in way to get a users Appdata Directory? For example on OS X it's in '~/Library//Application Support/'. I can get the OS just fine (sys.platform and then storing it in my own way; example: darwin = OS X, just for my own readability), and I can get the home directory just fine (expanduser), but I have no idea how to get the appdata directory. One way I could think of doing it would be to just detect the os and join the string on like so (completely untested, but an idea); if os == 'OS X': appdata_dir = os.path.join(home_dir, '/Application Support/') But then that arises the problem of cross platform compatibility. So is here a good, cross platform solution to this problem? Also, what is PEP, PEP8, etc? Is it like the Python programming layout conventions? Is there more to it than that? Thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: Getting the Appdata Directory with Python and PEP?
Thanks for the help on PEP, but I can't find a way to get the application support (appdata on Windows, no idea on Linux). If I do: print os.environ['HOME'] I get: '/Users/eamonn', as that is my home directory. But when I do: print os.environ['APPDATA'] I get an error. But when I do: print os.getenv('APPDATA') I get: None. Apparently os.getenv() works on Windows, but I can't see a way to get this on Mac. If I could get the names of this for different OS's I could just check the OS and run the appropriate code. Any help? -- https://mail.python.org/mailman/listinfo/python-list
Re: Getting the Appdata Directory with Python and PEP?
On Tuesday, November 26, 2013 7:40:50 PM UTC, Irmen de Jong wrote: > On 26-11-2013 19:09, Eamonn Rea wrote: > > > Thanks for the help on PEP, but I can't find a way to get the application > > support (appdata on Windows, no idea on Linux). If I do: > > > > > > print os.environ['HOME'] > > > > > > I get: '/Users/eamonn', as that is my home directory. But when I do: > > > > > > print os.environ['APPDATA'] > > > > > > I get an error. But when I do: > > > > > > print os.getenv('APPDATA') > > > > > > I get: None. > > > > > > Apparently os.getenv() works on Windows, but I can't see a way to get this > > on Mac. If I could get the names of this for different OS's I could just > > check the OS and run the appropriate code. > > > > > > Any help? > > > > > > > > > Maybe this module is of some use to you: > > https://pypi.python.org/pypi/appdirs > > > > It provides a unified Python API to the various OS specific 'user' directory > locations. > > > > Irmen I saw this, but I wanted to do it myself as I stated in the OP :) -- https://mail.python.org/mailman/listinfo/python-list
Re: Getting the Appdata Directory with Python and PEP?
Oh, sorry, I'm new to how Google Groups works. I wonder why it lays it out like that. Can it not just show quotes like the way that PHPbb does? I never thought of reading the source code, thanks! :-) Oh, and the last message is just spam :P -- https://mail.python.org/mailman/listinfo/python-list
Jython - Can't access enumerations?
Hello! I'm using Jython to write a game with Python/Jython/LibGDX. I wasn't having any trouble, and everything was going well, but sadly I can't access items in enumerations. If you know about the LibGDX library and have used it, you'll probably know about the BodyType enumeration for Box2D. I was trying to access the BodyType item in the enumeration. This didn't work, as Jython couldn't find the BodyType enumeration. I asked on the LibGDX forum and no one could help. So I'm hoping that someone here could help :-) So, is this a problem with LibGDX or Jython? I'm using the latest version of Jython. Thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: Jython - Can't access enumerations?
Ok, here's the code: body_def = BodyDef() # Imports the BodyDef class fine. body_def.type = BodyDef.DynamicBody # Says it can't find a module from LibGDX called BodyDef. All my code: from com.badlogic.gdx import Game, Gdx, Screen from com.badlogic.gdx.backends.lwjgl import LwjglApplicationConfiguration, \ LwjglApplication from com.badlogic.gdx.graphics import OrthographicCamera, GL20 from com.badlogic.gdx.graphics.g2d import SpriteBatch from com.badlogic.gdx.math import Vector2 from com.badlogic.gdx.physics.box2d import Box2DDebugRenderer, World, BodyDef, \ FixtureDef, PolygonShape import Player class Playing(Screen): def __init__(self): self.batch = None self.renderer = None self.world = None self.camera = None self.player = None self.player_body_def = None self.player_fixture_def = None self.player_shape = None def show(self): self.batch = SpriteBatch() self.renderer = Box2DDebugRenderer() self.camera = OrthographicCamera() self.player_body_def = BodyDef() self.player_fixture_def = FixtureDef() self.player_shape = PolygonShape() self.world = World(Vector2(0, -9.81), True) self.player_shape.setAsBox(0.5, 1) self.player_body_def.fixedRotation = True self.player_body_def.position.set(0, 0) self.player_body_def.type = BodyDef.DynamicBody self.player_fixture_def.density = 1 self.player_fixture_def.friction = 0.5 self.player_fixture_def.shape = self.player_shape self.player_fixture_def.restitution = 0.01 self.player = Player(self.world, self.player_body_def, self.player_fixture_def) def resize(self, width, height): pass def pause(self): pass def resume(self): pass def dispose(self): pass def render(self, delta): Gdx.gl.glClearColor(0, 0, 0, 1) Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) self.renderer.render(self.camera.combined, self.world) BodyDef.DynamicBody is defiantly in the BodyType Enumeration. I've tested it in Java. -- https://mail.python.org/mailman/listinfo/python-list
Change a file type in Python?
When opening a file, you'd say whether you want to read or write to a file. This is fine, but say for example later on in the program I change my mind and I want to write to a file instead of reading it. Yes, I could just say 'r+w' when opening the file, but what if I don't know if I'm going to do both? What if I have the user decide, and then later on I let the user change this. Is it possible to do so without opening the file again and using the same file object? Thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: Change a file type in Python?
Thanks for the help! Ok, I'll look into the mailing list. -- https://mail.python.org/mailman/listinfo/python-list