I'm trying to deploy a Python app on OSX that was built with PySide. py2app
packages it without issue, copying and linking a lot of PySide and Qt files in
the process. But then, when I try to run the built app, I get this error:
Traceback (most recent call last):
File
I have a Python script running on the default OSX webserver, stored
in /Library/WebServer/CGI-Executables. That script spits out a list of
files on a network drive, a la os.listdir('/Volumes/code/
directory/'). If I just execute this from the terminal, it works as
expected, but when I try to
I have a list of nodes, and I need to find a path from one node to
another. The nodes each have a list of nodes they are connected to,
set up like this:
class Node(object):
def __init__(self, connectedNodes):
self.connectedNodes = connectedNodes
nodes = {
1:
Never mind -- ditched the attempt and implemented Dijkstra.
--
http://mail.python.org/mailman/listinfo/python-list
I'm trying to pickle an instance of a class. It mostly works just fine
-- I can save the pickle to a file, restore it from that file, and
it's mostly okay. The problem is, some lists seem to disappear. For
example (snipped and crunched from the code giving me trouble):
---
class InitGame:
BTW, you should derive all your classes from something. If nothing
else, use object.
class textfile(object):
Just out of curiousity... why is that? I've been coding in Python for
a long time, and I never derive my base classes. What's the advantage
to deriving them?
--
Your class definition isn't right. It makes 'value' and 'journal'
class variables (Java lingo: static variables) as opposed to the
instance variables they should be. Here's a corrected version:
Woah, thanks. I can't believe I made such a stupid mistake. It's not
like I'm a newcomer to Python,
I'm working on a Python application right now that uses a large number
of audio assets. Instead of having a directory full of audio, I'd like
to pack all the audio into a single file. Is there any easy way to do
this in Python? My first instinct was to attempt to pickle all the
audio data, but
Do you mean like a zip or tar file?
http://docs.python.org/library/zipfile.htmlhttp://docs.python.org/library/tarfile.html
I had no idea you could access a single file from a ZIP or TAR without
explicitly extracting it somewhere. Thanks.
--
http://mail.python.org/mailman/listinfo/python-list
Anyway, this person also posted on mod_python list. One of the things
I highlighted there was that mod_python for some configurations is
multithreaded and as such they may not be properly protecting
variables if they are storing them at global scope. They haven't
responded to any comments
req.write(str(lab.game.settings.daemons))
del lab.game.settings
req.write(str(lab.game.settings.daemons))
lab.game.settings = lab.game.InitGame()
req.write(str(lab.game.settings.daemons))
Sorry, that should have been:
I have a number of functions that I need to pickle without necessarily
knowing their names in advance. My first thought was to put all the
functions in a class, then pickle the class, but it doesn't really
work like I expected it to.
import cPickle
class PickleClass:
Pickling the source code is much sturdier. It's very unlikely that
the same code runs differently in different interpreters. It's much
more likely that the same code runs the same, or not at all.
Okay, I've run into another problem. I've saved the code to a string,
so I can call it up when I
Never mind. Solved the problem by putting the functions in a class and
dumping that into a string. Then, when I need it, I executed the
string to get myself the class, then created an instance of that class
which gave me access to those functions along with the correct scope.
Probably not the
Why not use import ? Simply recreate the source file, if necessary, and
import it again.
Ah, you'd think it would be that easy :P
The problem with just importing a module is that the module is then
cached in memory. Multiple copies of the program are running on a
server, and each of them
Is there a way to make a Python app running in mod_python with zero
persistence? I have an app that should be resetting its variables
every time you access it, but sometimes -- and only sometimes -- the
variables persist through a couple refreshes. They'll even persist
through multiple browsers,
Okay, I'm at my wit's end. I have a Python app, running via
mod_python. There are variables in this app that, when changed, save
their changes to a pickled file tied to a session ID. Then, when the
page is accessed again, the variables are loaded from the respective
file.
But, when one user uses
Huzzah, another post.
I just discovered that even physically deleting the variable doesn't
work.
The module storylab.game has the class InitGame, which contains
daemons = {}.
A user runs the code, resulting in some values in daemons:
{'berry2': , 'berry3': , 'berry1': }. These are pickled.
The
are you an experienced python programmer?
Yeah, I'd link to think I'm fairly experienced and not making any
stupid mistakes. That said, I'm fairly new to working with mod_python.
All I really want is to have mod_python stop caching variables. This
seems like it should be easy enough to do, but
I'm running into a problem that's rapidly reaching keyboard-smashing
levels. I'm trying to import a module into Python, but it seems like
Python is almost randomly loading the module from an entirely
different directory, one that shouldn't be in the module search path.
When I tell Python to load
Okay, I'm going out of my mind. I have three directories -- 'act1',
'act2', and 'act3'. Each of these has a module named 'story'.
Through mod_python, I need to load 'story' in the directory 'act1'. I
do it like this:
req.content_type = text/html
sys.path.append(os.path.dirname(
Here's another clue: if I'm trying to run the script from the
directory 'act1', but it's loading the module from 'act2', if I rename
the module directory in 'act2' and refresh, the module still reports
that it's running from '/home/www/---/docs/act2/story/game.pyc'...
even though that files no
And more madness...
Executed from inside 'act1', which contains the directory / module
'story':
directory = os.path.dirname(__file__)
req.write(str(directory))
story = apache.import_module('story', path=[directory])
Results:
File /home/www/---/docs/act1/play.py,
Son of a bitch. It gets worse.
Executed from inside 'act1', which contains the directory / module
'story':
directory = os.path.dirname(__file__)
req.write(str(directory))
story = apache.import_module('story', path=[directory])
Results:
/home/www/---/docs/act1
'req.write(story.game.Save())' returns '/home/www/--/docs/act2/
storylab/game.pyc' as the file being accessed.
Sorry, that should have read:
'req.write(story.game.Save())' returns
'/home/www/--/docs/act2/story/game.pyc' as the file being accessed.
--
And finally, an epilogue.
So, the problem lies with how Python cached the modules in memory.
Yes, the modules were in two different locations and yes, the one that
I specified using its direct path should be the one loaded. The
problem is, the module isn't always loaded -- if it's already in
I've been trying to read up on this, but I'm not sure what the
simplest way to do it is.
I have a list of string. I'd like to check to see if any of the
strings in that list matches another string.
Pseudocode:
if two in [one, two, three, four]:
return True
Is there any built-in iteration
Damn you, Python, and your loose documentation! It never occurred to
me to actually TRY my pseudocode, since I couldn't find anything on
that type of statement. Anyway, feel free to ignore me from now on.
--
http://mail.python.org/mailman/listinfo/python-list
I've been trying to tackle this all morning, and so far I've been
completely unsuccessful. I have a binary file that I have the
structure to, and I'd like to read it into Python. It's not a
particularly complicated file. For instance:
signature char[3] GDE
version uint32 2
signature, version, attr_count = struct.unpack('3cII',
yourfile.read(11))
This line is giving me an error:
Traceback (most recent call last):
File test.py, line 19, in module
signature, version, attr_count = struct.unpack('3cII',
file.read(12))
ValueError: too many values to unpack
--
CORRECTION: '3cII' should be '3sII'.
Even with the correction, I'm still getting the error.
--
http://mail.python.org/mailman/listinfo/python-list
Sorry, I had posted the wrong error. The error I am getting is:
struct.error: unpack requires a string argument of length 12
which doesn't make sense to me, since I'm specifically asking for 11.
Just for kicks, if I change the line to
print struct.unpack('3sII', file.read(12))
I get
Taking everything into consideration, my code is now:
import struct
file = open(test.gde, rb)
signature = file.read(3)
version, attr_count = struct.unpack('II', file.read(8))
print signature, version, attr_count
for idx in xrange(attr_count):
attr_id, attr_val_len = struct.unpack('II',
I have mod_python running on my server, but when I chance a Python
file on the server, Apache needs to be restarted in order to have the
changes take effect. I assume this is so mod_python can run
persistently, but it's becoming quite a headache for development. Is
there a way to turn off the
I'm having some trouble understanding how Python handles variables
across multiple modules. I've dug through the documentation, but I
still find myself at a loss.
When you import a module, are you creating an instance of the
variables within? For instance, if I have one file, variables.py,
which
Just wirte test code !
variables.py:
myvar = 5
print myvar
foo.py:
from variables import *
def PrintVar():
print myvar
bar.py:
from variables import *
from foo import *
print myvar
myvar = 2
print myvar
PrintVar()
python bar.py
first read this to learn how objects and variables work in Python:
http://effbot.org/zone/python-objects.htm
and then read this to learn how from-import works, and when you're
supposed to use it:
http://effbot.org/zone/import-confusion.htm
hope this helps!
Awesome. After
Is it possible to change the content of a function after the function
has been created? For instance, say I make a class:
class MyClass:
def ClassFunction(self):
return 1
And I create an object:
MyObject = MyClass()
Is there any way to
38 matches
Mail list logo