Re: Spaces in path name
By mapping network drives in windows I can get past these issues with path names. Thanks, David "Tim Golden" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > David S wrote: >> Gets me further but still seems to be issue with space after 'Program' as >> code tries to run 'C:\Program'. Don't understand what is going on here... > > Slight apologies as I haven't followed this thread closely, but using the > Acrobat Reader executable, which is, I think, good enough for the > purposes of illustration: > > > import os > import subprocess > > filename = r"C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe" > doc = r"C:\Program Files\Adobe\Reader 8.0\Resource\ENUtxt.pdf" > > print os.path.isfile (filename) > > os.system (filename + " " + doc) > > os.system ('"%s" "%s"' % (filename, doc)) > > subprocess.call ([filename, doc]) > > > > os.path.isfile succeeds > os.system (filename) fails as your code does > os.system ('"%s"' ...) fails even though both strings are requoted > subprocess.call (filename) succeeds > > The latter, at least, is because the subprocess module > has some special-case handling for exactly this situation > on MS Windows, while os.system doesn't. > > Now, ultimately, I don't know if this really helps your > exact situation but it least it should be clear what will > and what won't work. Conclusion: use subprocess.call if > you can. > > TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Spaces in path name
Hi, Gets me further but still seems to be issue with space after 'Program' as code tries to run 'C:\Program'. Don't understand what is going on here... using "java.exe" from "C:\Program Files\Java\jdk1.6.0_01" using "C:\Program Files\apache-ant-1.7.0\bin\ant.bat" for building Building from E:\Red5\red5_server\install\windows Cleaning old directories... Compiling Java 1.5 version... 'C:\Program' is not recognized as an internal or external command, operable program or batch file. Traceback (most recent call last): File "installer.py", line 132, in main() File "installer.py", line 128, in main builder.build() File "installer.py", line 70, in build self.compile(self.ant_cmd, os.path.join(red5_root, 'build.xml'), '1.5', 'cle an', 'installerdist') File "installer.py", line 26, in compile assert os.system('%s -quiet -Djava.target_version=%s -buildfile %s%s' % (ant , version, script, args)) == 0 AssertionError "Bryan Olson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > David S wrote: >> I get >> >> ERROR: ""C:\Program Files\apache-ant-1.7.0\bin\ant"" does not exist >> >> If I cut the path statement here and paste it next to a windows XP >> command prompt ant is invoked. >> >> The python code here is >> if not os.path.isfile(ANT_CMD): >> error('"%s" does not exist' % ANT_CMD) > > There you don't want the quotes within the string. On my MS-Win box: > > >>> import os > >>> os.path.isfile(r'C:\Program Files\Windows NT\dialer.exe') > True > >>> print os.path.isfile(r'"C:\Program Files\Windows NT\dialer.exe"') > False > > > -- > --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: Spaces in path name
Hi, Using "C:\Program Files\apache-ant-1.7.0\bin\ant.bat" just gives me the same result. David "Dennis Lee Bieber" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Fri, 14 Mar 2008 04:37:12 GMT, "David S" <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > >> If I cut the path statement here and paste it next to a windows XP >> command >> prompt ant is invoked. >> >> The python code here is >> if not os.path.isfile(ANT_CMD): >> error('"%s" does not exist' % ANT_CMD) >> > Any chance the /filename/ is something like "ant.exe" > >>>> pyt = "e:/python24/python" >>>> if not os.path.isfile(pyt): > ... print "%s does not exist" % pyt > ... > e:/python24/python does not exist >>>> pyt = "e:/python24/python.exe" >>>> if not os.path.isfile(pyt): > ... print "%s does not exist" % pyt > ... >>>> > > Remember, under Windows, files with certain extensions are > executable /without/ needing the extension on the command line -- unlike > Linux... > > My eclipse install has: ant.bat, ant.cmd, and ant.jar files, and > which (if they are in the same directory) gets picked when the extension > is not specified is beyond my current knowledge -- might depend on the > order of the extensions specified in the > > C:\Documents and Settings\Dennis Lee Bieber>echo %pathext% > .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.pyw;.py;.pyo;.pyc;.tcl > > (okay, the ant.jar won't be picked ) > > -- > Wulfraed Dennis Lee Bieber KD6MOG > [EMAIL PROTECTED] [EMAIL PROTECTED] > HTTP://wlfraed.home.netcom.com/ > (Bestiaria Support Staff: [EMAIL PROTECTED]) > HTTP://www.bestiaria.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Spaces in path name
Hi, I get ERROR: ""C:\Program Files\apache-ant-1.7.0\bin\ant"" does not exist If I cut the path statement here and paste it next to a windows XP command prompt ant is invoked. The python code here is if not os.path.isfile(ANT_CMD): error('"%s" does not exist' % ANT_CMD) David "Mensanator" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] On Mar 13, 5:16 pm, "David S" <[EMAIL PROTECTED]> wrote: > Hi, > > I have some code in which I have to change some path names to get it to > work. The original code seems to have assumed that path names would not > have > any embedded spaces. > > I am not sure how to write the following line so when used in my script > the > path will be found. > > ANT_CMD = r'C:\Program Files\apache-ant-1.7.0\bin\ant' Try ANT_CMD = r'"C:\Program Files\apache-ant-1.7.0\bin\ant"' > > Regards, > David -- http://mail.python.org/mailman/listinfo/python-list
Spaces in path name
Hi, I have some code in which I have to change some path names to get it to work. The original code seems to have assumed that path names would not have any embedded spaces. I am not sure how to write the following line so when used in my script the path will be found. ANT_CMD = r'C:\Program Files\apache-ant-1.7.0\bin\ant' Regards, David -- http://mail.python.org/mailman/listinfo/python-list
Handling global variables (Newbie)
Hi, I have an error occurring at self.build_root = os.path.abspath(os.path.split(__file__)[0]) The error states 'NameError: global name '__file__' is not defined' In Python 2.5 I ran my script as a module in IDLE gui. How does _file_ get defined? Yours, David -- http://mail.python.org/mailman/listinfo/python-list
Re: chained attrgetter
Ah, pretty Python. Thanks, all. -- http://mail.python.org/mailman/listinfo/python-list
chained attrgetter
Does something like operator.getattr exist to perform a chained attr lookup? I came up with the following, but I can not help but think it is already done and done better. Peace, David S. def compose(funcs): """ return composite of funcs this does not support extended call syntax, so each func can only take a single arg >>> from operator import add >>> funcs = [lambda x:add('ANSWER: ', str(x)), lambda x:add(x,100)] >>> compose(funcs)(9) 'ANSWER: 109' """ def _func(arg): return reduce(lambda v,f: f(v), iter(funcs[::-1]), arg) return _func def chained_attrgetter(cattr): """ >>> class A: pass ... >>> a1 = A >>> a1.a2 = A >>> a1.a2.a3 = "Hey, now!" >>> chained_attrgetter("a2.a3")(a1) 'Hey, now!' """ return compose([attrgetter(attr) for attr in cattr.split('.')[::-1]]) -- http://mail.python.org/mailman/listinfo/python-list
Re: distutils
Dan Crosta sccs.swarthmore.edu> writes: > I don't understand -- you can install multiple scripts with a single > setup.py. Do you want finer-grained control over which are installed by > a single invocation of setup.py? In that case, you should re-read the > distutils docs about sub-classing portions of the setup process. The > documentation for the Python 2.4.2 distribution is more complete than in > 2.3.5. Again, thank you. To clarify, I want to have a separate install for--potentially--each script. I imagined that I could put a setup.py in each folder that a script lived and somehow indicate the root of my source so that distutils could find other modules that the scripts use. Perhaps, I have not organized things appropriately--I do not know. I will try to read the doco again and see if I can infer some best practices. Peace, David S. -- http://mail.python.org/mailman/listinfo/python-list
Re: distutils
Dan Crosta sccs.swarthmore.edu> writes: > > fsi\ > > - common\ # some modules > > - db\ # some modules > > - someutility\ # my script > > > > Your setup.py should live in fsi/setup.py. try: > Thank you. This introduces a new problem for me. I have other scripts that I want to install likewise. But now I have to overwrite setup.py for each install. Alternatively, I can create script1setup.py, script2setup.py, etc. That would be fine except that there are other files, ie. MANIFEST.IN and README, that need to be there too. I have not found a way to similarly rename these. Finally, it seems odd that I should have so many XXXsetup.py scripts in my package root directory. Thanks again, David S. -- http://mail.python.org/mailman/listinfo/python-list
distutils
I have a what I a typical source tree, something like: fsi\ - common\ # some modules - db\ # some modules - someutility\ # my script I would like to create a setup script to install my script as a script as well as the modules that is depends on, but where should the setup.py file live? If I put it in ./someutility/ it can not find fsi.common or fsi.db. package_dir does not seem to work and I am confused. The documentation is, I am sure thorough, but something that fit on fewer pages would help. So I appreciate any help for this particular problem as well as any suggestions for other documentation or guides to using distutils. Peace, David S. -- http://mail.python.org/mailman/listinfo/python-list
Concurrency, I guess
I have a simple intranet web app whose job is to synchronize a couple of databases. The web part is that you can change settings such as how often the sync should happen, force the sync, or see the log. Since it runs periodically, I want the process that does the db sync to run happily along but be aware of when a setting is changed. So in my simple mind I envision 2 threads: start the sync process, start the web server and hope that when the web server handles some request and changes a setting, the sync process knows about it. The final requirement is that the server can know if the sync process is running already should someone try to manually start the sync. Anyway, I have tried messing around with the threading module and referenced some examples I have come across, but to no avail. Fundamentally I expected that when I change a global variable in 1 thread, the new value would be picked up in any other thread. This does not appear to be the case. (I understand that there are lots of potential issues with this but only 1 thread ever shanges the value anyhow.) I have not even tried blocking the sync process if it is already going. The candygram module (http://candygram.sourceforge.net/) might be the way for me to go, but I would still like to understand this pretty basic question. So any insight, advice, or references on the problem as described would be very welcome. It seems it must be fairly common. Peace, David S. -- http://mail.python.org/mailman/listinfo/python-list
Re: standard doc style for method signatures
David S. alumni.tufts.edu> writes: > > Is there a generally accepted way to denote method signatures---that is, > expected type or required interface for each argument. > Here is an answer: http://python.org/peps/pep-0257.html http://www.python.org/peps/pep-0008.html -- http://mail.python.org/mailman/listinfo/python-list
standard doc style for method signatures
Is there a generally accepted way to denote method signatures---that is, expected type or required interface for each argument. -- http://mail.python.org/mailman/listinfo/python-list
Re: global variables
M.N.A.Smadi grads.ece.mcmaster.ca> writes: > I need to have a varaible that will contain a value that will be > modified in one file, and when coming back to the same file it > should retain the same value. You must import the module in which the variable lives and qualify it appropriately. So, if you have the following files trash1.py var = 1 trash2.py import trash1 trash1.var = 2 trash3.py import trash1 print trash1.var you can run the interpreter and: >>>import trash2 >>>import trash3 2 -- http://mail.python.org/mailman/listinfo/python-list
Re: reuse validation logic with descriptors
Steve Holden holdenweb.com> writes: > You want assignment to a method-local variable to turn an attribute into > a property? That's programming with a magic wand ... > > That will depend on the value returned by property access, surely? > > I suspect you are a little confused about properties and descriptors. > > regards > Steve Quite confused, actually, which was the reason for my original post. Thanks again to those who helped me and any other confused folks understand this bit of Python that much better. Peace, David S. -- http://mail.python.org/mailman/listinfo/python-list
Re: reuse validation logic with descriptors
Steven Bethard gmail.com> writes: > > P.S. If you haven't already, you should read > http://users.rcn.com/python/download/Descriptor.htm a couple of times. > It took me until about the third time I read it to really understand > what descriptors were doing. The big thing to remember is that for an > instance b, > b.x > is equivalent to > type(b).__dict__['x'].__get__(b, type(b)) > and for a class B, > B.x > is equivalent to > B.__dict__['x'].__get__(None, B) > Note that 'x' is always retrieved from the *type* __dict__, not from the > *instance* __dict__. Steve, and others, thanks for the help. This and Michael Spencer's reply at http://article.gmane.org/gmane.comp.python.general/390478 have been very helpful in getting the descriptor definition clear. For me, it has taken reading http://users.rcn.com/python/download/Descriptor.htm about 4 times along with your help to get this straight. Peace, David S. -- http://mail.python.org/mailman/listinfo/python-list
Re: reuse validation logic with descriptors
Steven Bethard gmail.com> writes: > > David S. wrote: > > I am looking for a way to implement the same simple validation on many > > instance attributes and I thought descriptors > > (http://users.rcn.com/python/download/Descriptor.htm) looked like the > > right tool. > > > Looks like you're trying to reinvent the property descriptor. Try using > the builtin property instead: > > py> def getchar(self): > ... if not hasattr(self, '_char'): > ... self._char = None > ... return self._char > ... > py> def setchar(self, value): > ... if not len(value) == 1: > ... raise ValueError > ... self._char = value > ... > py> singlechar = property(getchar, setchar) > py> class Flags(object): > ... a = singlechar > ... b = singlechar > ... > py> f = Flags() > py> f.a = "a" > py> f.b = "bb" > Traceback (most recent call last): >File "", line 1, in ? >File "", line 3, in setchar > ValueError > This still fails to work for instances variables of the class. That is if I use your property in the following: py> ...class Flags(object): ...def __init__(self): ... a = singlechar ... py> f = Flags() py> f.a = "a" Now f.a.__class__.__name__ returns 'str'. So the property was not used at all. Also, it seems that using a property, I can not do the other useful things I can do with a proper class, like provide an __init__, __str__, or __repr__. Again, thanks, David S. -- http://mail.python.org/mailman/listinfo/python-list
reuse validation logic with descriptors
I am looking for a way to implement the same simple validation on many instance attributes and I thought descriptors (http://users.rcn.com/python/download/Descriptor.htm) looked like the right tool. But I am confused by their behavior on instance of my class. I can only get the approximate behavior by using class variables. I am looking for something like: class SingleChar(object): def init(self): self._char = None def __set__(self, instance, value): if not len(value) == 1: raise ValueError self._char = value def __get__(self, instance, owner): return self._char class Flags(object): def __init__(self): self.a = SingleChar() self.b = SingleChar() f = Flags() f.a = "a" f.b = "bb" exceptions.ValueError ValueError: What I actually get when I try this is f.a and f.b become str instances. Meanwhile, I can get this to work, except that a and b are now just class attributes. class CFlags(object): a = SingleChar() b = SingleChar() What is the proper and clean way to accomplish this sort of thing, so that you can reuse the logic in for many instance attributes across multiple classes? Thanks, David S. -- http://mail.python.org/mailman/listinfo/python-list
Re: huge help for interactive python
David S. alumni.tufts.edu> writes: > I am sure it can be improved, but it was easy. By the > way, it generates LaTeK. LaTeX, rather. -- http://mail.python.org/mailman/listinfo/python-list
huge help for interactive python
If you are using ipython on Windows then you will have made sure you have Gary Bishop's readline library as instructed in the ipython install directions found at: http://ipython.scipy.org/ Even if you use the standard commandline tool, installing readline makes the basic command line a lot easier to use. (For some reason, I much prefer it to IDLE or any of the other GUI-wrapped interpreters.) I could not find a list of the keyboard commands that readline supports, so I generated: http://fsinnovations.net/share/keymap.pdf NOTES: You can checkout the script that generates this at: http://fsinnovations.net/share/readlinekeymap.py This uses Ken Seehof's Python Cookbook recipe found at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81982 I am sure it can be improved, but it was easy. By the way, it generates LaTeK. To install readline, get it at: http://sourceforge.net/projects/uncpythontools. You will also need the ctypes library by Thomas Heller, found at: http://starship.python.net/crew/theller/ctypes -- http://mail.python.org/mailman/listinfo/python-list
Re: [newbie]How to install python under DOS and is there any Wxpython can be installed under dos?
john san att.net> writes: > > How to install python under DOS and is there any Wxpython-like can be > installed under dos? > > Thanks. > If you are looking for Windows installers then, yes. See: http://www.wxpython.org/ http://www.wxpython.org/download.php#binaries If you are really looking for dos binaries, I guess you need to build them yourself. -- http://mail.python.org/mailman/listinfo/python-list
subprocess problem on Windows in IDLE and PythonWin
Python 2.4 on Windows XP In the python command-line the following works fine: >>> from subprocess import * >>> p = Popen('dir', stdout=PIPE) >From within IDLE or PythonWin I get the following exception: Traceback (most recent call last): File "", line 1, in -toplevel- p = Popen('dir', stdout=PIPE) File "c:\python24\lib\subprocess.py", line 545, in __init__ (p2cread, p2cwrite, File "c:\python24\lib\subprocess.py", line 605, in _get_handles p2cread = self._make_inheritable(p2cread) File "c:\python24\lib\subprocess.py", line 646, in _make_inheritable DUPLICATE_SAME_ACCESS) TypeError: an integer is required Note it works fine on Linux also. I tested it with >>> p = Popen('ls', stdout=PIPE) ... and had no trouble. -- http://mail.python.org/mailman/listinfo/python-list