Re: pipes python cgi and gnupg
On Dec 28 2007, 7:07 pm, [EMAIL PROTECTED] wrote: snip form = cgi.FieldStorage() if not form.has_key(pass): print Enter password filename = test.gpg pass = form.getvalue(pass).strip() os.system(gpg --version gpg.out) os.system(echo %s | gpg --batch --password-fd 0 --decrypt %s d.out %(pass,filename)) The last time I checked, pass is a reserved word in Python. Since you are using a reserved word as a variable, maybe that's what's messing with your output? -- http://mail.python.org/mailman/listinfo/python-list
Re: Layer 2 socket connection
On Aug 16, 5:03 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: snip I use impacket for stuff like that, seehttp://oss.coresecurity.com/projects/impacket.html Cheers Rich. Thanks, Rich - I'll have a look -- http://mail.python.org/mailman/listinfo/python-list
Layer 2 socket connection
Hello all - I'm looking at trying to write a python script to connect to a layer 2 bridge (no IP available). Looking at the sockets function, it's not clear if I can connect using only the mac address - it appears to want either a broadcast address or a specific IP address. Can anyone give me a clue on opening a layer 2 socket in Python? -- http://mail.python.org/mailman/listinfo/python-list
Re: Layer 2 socket connection
On Aug 15, 12:05 pm, Martin v. Löwis snip If your operating system supports the PF_PACKET protocol family, you can try to use that. Python only wraps the socket interface of the operating system, so if the system's socket implementation has no facility for that, Python cannot expose it to you, either. Regards, Martin I take it this means Non-Unix variants may have problems :) Thanks, Martin. I'll have a look at that. I'm working on a Linux platform, but there may be a need later on to work with an MS platform as well (something for the boss). -- http://mail.python.org/mailman/listinfo/python-list
Re: if __name__ == 'main': passing an arg to a class object
On Apr 27, 2:08 pm, gtb [EMAIL PROTECTED] wrote: The lines if __name__ == 'main': someClass().fn() appear at the end of many examples I see. Is this to cause a .class file to be generated? These are samples to give the programmer an idea of how the code is supposed to work. If you cut/paste these examples in your working code, you have to change the source to something that actually works. BTW - Python does not use separate *.class files - *.py scripts (text files) are byte compiled to *.pyc files for the python interpreter. Would you perchance be referring to Java programming (which is a different newsgroup)? The last line of the sample below has a string parameter. When I mimicked this I got an error stating that the class constructor did not take an arg, which seems correct. Thanks, gtb # Generated by MaxQ [com.bitmechanic.maxq.generator.CompactGenerator] from CompactTest import CompactTest class MaxQTest(CompactTest): # Recorded test actions. def runTest(self): self.msg('Test started') # ^^^ Insert new recordings here. (Do not remove this line.) # Code to load and run the test if __name__ == 'main': MaxQTest('MaxQTest').Run() In this case, the routine was called from a python command line, so the __name__ variable is set to __main__. This is a standard Python trick to see if you are running the file as a stand alone script, or if it was imported as a module (typically used with code that was written that can be either standalone or used as part of a different package - good for unit testing). The example above { MaxQTest(MaxQTest).Run() } tells me either you're trying to run a threaded application, or you're used to Java programming. Again, would you be wanting to talk to a Java newsgroup rather than a Python newsgroup? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to create/ref globals in an alternate namespace?
On Apr 27, 2:33 pm, Steven W. Orr [EMAIL PROTECTED] wrote: On Friday, Apr 27th 2007 at 14:07 -0700, quoth James Stroud: snip I'm trying to see if by being clever, I can factor out the common code of the four different functions and still end up with what they create ending up in the namespaces where they are intended to reside in. Does this make sense or am I way off base? snip You may be trying to get too clever. If what you're trying to do is what I think you're trying to do, I would suggest looking at how the logging module handles globals and functions for an example. -- http://mail.python.org/mailman/listinfo/python-list
Re: Been a while...
On Mar 22, 11:48 am, John Salerno [EMAIL PROTECTED] wrote: snip http://www.pythonchallenge.com Ugh, I gave up on that site a long time ago! :) I got stuck on 34 a couple of months ago and haven't had time to go back to it. Fun challenge. -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing Indented Text (like parsing Python)
On Mar 11, 2:34 am, Mike Schinkel [EMAIL PROTECTED] wrote: Hi, I'm relatively new to Python but have lots of prior programming experience as a developer, instructor, and author (ASP/VBScript/SQL Server and Clipper.) snip -- -Mike Schinkelhttp://www.mikeschinkel.com/blogs/http://www.welldesignedurls.orghttp://atlanta-web.org-http://t.oolicio.us Well, when the Master Chief and I were writing Clipper code too many moons ago, we wrote a basic script that read the text, along with a list of keywords (indent kw, matching detent kw). All leading whitespace was removed as the line was read, then keeping track of the appropriate current level of indent, re-write the leading whitespace. For printouts, we would add the appropriate IBM characters for lines to keep track of matching indent/detent kw's were and could keep track of where the routines would fall off due to incorrect detent kw usage. If you don't know what the context is as far as indent/detent kw's are, then it gets to be a problem figuring it out unless there is specified characters used to indicate indent/detent issues. -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested if and expected an indent block
[EMAIL PROTECTED] wrote: Greetings: snip elif q.lower() == some# s in some is highlighted snip Any ideas? Thanks in advance. Keith Would the missing colon have something to do with it? elif q.lower() == some: -- http://mail.python.org/mailman/listinfo/python-list
Re: String Formatting
OriginalBrownster wrote: snip Example If i had a list:bread, butter, milk def get_word(s, which=1, sep=','): return s.split(sep)[which-1].strip() get_word('bread, butter, milk') 'milk' -- http://mail.python.org/mailman/listinfo/python-list
Re: String Formatting
alisonken1 wrote: OriginalBrownster wrote: snip Example sorry, forgot the '... everything after the last comma ...' part. -- http://mail.python.org/mailman/listinfo/python-list
Re: String Formatting
Sorry, missed an option in there: def get_word(s, which=1, sep=','): return s.split(sep)[which-1].strip() get_word('bread, butter, milk') 'milk' get_word('bread, butter, milk') 'bread' get_word('bread, butter, milk', 3) 'milk' get_word('bread is brown, butter is yellow, milk is white') 'bread is brown' get_word('bread is brown, butter is yello, milk is white', 3) 'milk is white' -- http://mail.python.org/mailman/listinfo/python-list
Re: simple dbus python problem ... please help
bob wrote: snip bus = dbus.Bus (dbus.Bus.TYPE_SYSTEM) hal_service = bus.get_service ('org.freedesktop.Hal') hal_manager = hal_service.get_object ('/org/freedesktop/Hal/Manager', 'org.freedesktop.Hal.Manager') snip It appears that bus.get_service() has been deprecated and deleted. Not sure about the changes, so anyone else who can help please jump in. -- http://mail.python.org/mailman/listinfo/python-list
Re: stderr, stdout, and errno 24
Wesley Henwood wrote: I've checked and double checked my code and I am closing all files explicitly after opening them. The only possibliy I can think of is Python opening files each time I run a script, or each time imput to stderr or stdout is redirected. snip The problem I think is that stout and stderr are not shared with each invocation. Since you're calling a python interpreter, the stdout/stderr from the C++ program is not inherited - so now everytime you call the python script, it's creating a new process. With each new process, you're creating a new stdout/stderr handle, and if you're calling outside of C++ relatively quickly (say more than 100 times a minute), then the old stdout/stderr handles have not had a chance to be garbage collected - hence, you get too many files open errors. The workaround would possibly be to create a Python thread or create a stdout fifo and a stderr fifo and have your script redirect these outputs through the fifo buffers that you're C++ code can listen to. Not sure how to do either one in MS environments, so you'll have to ask someone else how to work with them. -- http://mail.python.org/mailman/listinfo/python-list
Re: Duplex communication with pipes - is possible ?
snip readlines () will try to read until the stream/socket is closed. Try to read only one line. This of course means that you cannot sent \n as part of the data, you have to escape them somehow. snip If I remember correctly, if you want to pass '\n' so readline won't stop, you should be able to escape the escape '\\n', then remove the extra '\' when actually processing. Of course, readline will continue to read until buffer filled or a real '\n' is passed (g). -- http://mail.python.org/mailman/listinfo/python-list
Re: ValueError: too many values to unpack
[EMAIL PROTECTED] wrote: snip 56 records were different Type, FileType, Item, Hash, Path, Size, CullCd, Ext, DtCr, DtLMd, DtLAc Traceback (most recent call last): File C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py, line 310, in RunScript exec codeObject in __main__.__dict__ File Q:\PythonScripts\InventoryCompareCase.py, line 234, in ? main() File Q:\PythonScripts\InventoryCompareCase.py, line 117, in main for (Type,FileType,Item,Hash,Path,Size,CullCd,Ext,DtCr,DtLMd,DtLAc) in infoDiffs : ValueError: too many values to unpack Thanks Retheesh The too many values to unpack indicates you don't have enough variables in the [for (...) in infoDiffs: ] construct. You also may want to change some of the names; although Type (variable name) and type (python function) should be different, it's good practice to not use names that are similar to functions. -- http://mail.python.org/mailman/listinfo/python-list
Re: find all index positions
[EMAIL PROTECTED] wrote: hi say i have string like this astring = 'abcd efgd 1234 fsdf gfds abcde 1234' if i want to find which postion is 1234, how can i achieve this...? i want to use index() but it only give me the first occurence. I want to know the positions of both 1234 thanks == def getAllIndex(aString=None, aSub=None): t=dict() c=0 ndx=0 while True: try: ndx=aString.index(aSub, ndx) t[c]=ndx ndx += 1 c += 1 except ValueError: break return t === This will return a dictionary of what was found; i.e., getAllIndex('abcd 1234 efgh 1234 ijkl', '1234') {0: 5, 1: 15} -- http://mail.python.org/mailman/listinfo/python-list
Re: find all index positions
Scott David Daniels wrote: [EMAIL PROTECTED] wrote: SNIP print list(positions('1234', 'abcd efgd 1234 fsdf gfds abcde 1234')) prints: [10, 31] Nicer than mine ;) Shows I need to get a job where I use python more! -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging vs printing
Leo Breebaart wrote: SNIP Also, assume that I have set it up as above. Now I want certain other print statements to go to sys.stderr alone. If I understand the docs correctly (possibly I don't), the way to do this is to start attaching explicit StreamHandlers and whatnot. Whereas with print, I can say print sys.stderr, msg. SNIP Something else to consider, every time your script calls print sys.stderr, msg, it is making another file open request. I've run across situations where this format will actually cause a system to return too many open files error. As was pointed out earlier, it's much easier to learn how to use the logging facility and create a default stdout logger as well as a secondary stderr logger that only maintains one file handle than to try to find out where you're getting some errors that are not script errors but system limit errors. The other nice aspect of using the logging facility is the availability of changing the logger to save output to a file or stdout/stderr than to try and go through a more-than-one-file program. It's easy to learn how to redirect stdout/stderr within a script, but it's usually more flexible to use the logging facility that's already been included. Before the logging module was included in the library, I usually ended up writing my own logging module to do the same thing. Especially since the logger allows you to specify levels. For example, I typically have my logging facility setup as follows: 10 - Very basic logging - typically main routine changes 20 - Log imports 30 - Log class instantiation 40 - Log module calls 50 - Log function calls The other aspect of using the logging facility, you can also define your own in-between log levels: 51 - Entering function 52 - Exiting function 53 - Function sub-routines 60 - Everyhing under the sun As part of the configParser options: -v : Increment logging level by 1 level for every -v option on command line -loglevel=level : Specify log level -logfile=filename : File to save stdout messages -errfile=filename : File to save stderr messages Once you get used to the logging module, it's hard to go back to using file redirects and the sometimes system limits troubleshooting in larger programs. -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing options around your program
Leo Breebaart wrote: I have another question where I am not so much looking for a solution but rather hoping to get some feedback on *which* solutions people here consider good Pythonic ways to approach a issue. The situation is this: I am writing fairly large console scripts in Python. They have quite a few command-line options, which lead to configuration variables that are needed all over the program (e.g. the --verbose option alone is used by just about every function and method). SNIP One question I have is about the --verbose option. If you're doing something that is equivalent to logging to file | console, rather than continuing to pass the '--verbose' flag around, why not just use the built-in logging facility to manage the extra output? By having the different modules call logging( level, message) throughout your programs, you only need to set the initial level from where you're checking options (whether from command line or configuration file) rather than having to pass the '--verbose' option around. -- http://mail.python.org/mailman/listinfo/python-list
Re: Drop Down Menus...
Hello Bruce - bruce wrote: Hi... Never used python, but I have a question regarding Drop Down Menus. Does Python allow me to create a website, that will permit the user to create Drop Down menus that can be initiated with the right mouse click? If it can, is it fairly easy to implement? If you are talking about client-side menu's, you should be looking at Java or Java-Script. Python is good at server-side scripting, but there is no widely installed python interpreter on peoples browsers that would work, whereas java and javascript are pretty much the standard in client-side scripting in web browsers. -- http://mail.python.org/mailman/listinfo/python-list
Re: ConfigParser and multiple option names
Benji York wrote: SNIP I generally do this: dirs = /home/florian /home/john /home/whoever ...and then use str.split() in my program. -- Benji York The only problem with this would be if you plan on updating the config file later in the program - I don't think ConfigParser would write the new config file with these options setup this way. -- http://mail.python.org/mailman/listinfo/python-list
Re: What do you use __init__.py for?
[EMAIL PROTECTED] wrote: snip But what other uses does the '__init__.py' script have? What do you use it for? snip __init__.py is used for initialization of the package - similar to __init__() in a function or class declaration. One example would be if you create a package with generic database methods - you can, in the __init__.py file, configure which actual database drivers are used but only have to write your routines to the generic setup. Module structure: db directory __init__.py db directory/my_bsddb -- files for bsddb access go here db directory/my_postgresql -- files for postgresql access go here Example __init__.py (pseudo coded, not python coded): if (configure_database == berkelyDB): import my_bsddb as db elif (configure_database == postgresql): import my_postgresql as db else: log(DB config error - no valid datbase selected) Then, in your routines, you only need to call db.method/function -- http://mail.python.org/mailman/listinfo/python-list
Re: Advanced Treeview Filtering Help
Your question was answered on PyGTK mailing list. Please, don't crosspost. Where is the pygtk mailing list? -- http://mail.python.org/mailman/listinfo/python-list
Re: error
Will I get the same error running main if the total number of lines in the smaller modules is 10k? Not sure if this would solve your problem, but I noticed the 10K filesize. I don't know about other programmers, but I find it much easier to keep track of stuff if I keep the individual file sizes less than 10K in size. Another thought would be to create a module with several submodules of grouped functionality (similar to the xml module where submodules dom/parsers/sax are) - this way it's easier to keep track of the differences/problems. -- http://mail.python.org/mailman/listinfo/python-list
Re: How should multiple (related) projects be arranged (structured) and configured so that they can share code, have a related package structure and enable proper unittesting, and ensuring no namespac
It can be fun when talking several subjects in the same post g. In this case, it was just a matter of thinking about what the main question was about unit testing code that also required other production packages, but with the caveats that he didn't want to duplicate packages just to test code or hack around during testing, then have to change the test code when it was time to add to production code (which may introduce more errors that the testing would not find). CVS just found it's way from one of the suggestions as a side note in reply to a minor point about how to keep track of test code without messing with/duplicating production code. -- http://mail.python.org/mailman/listinfo/python-list
Re: Raising a specific OSError
To raise a specific error, just find the error that you want to raise, then give the error a text string to print: ex. raise IOError(This raises an IO error) On the stderr output, when the routine hits this line, you will get: raise IOError(This raises an IOError) Traceback (most recent call last): File stdin, line 1, in ? IOError: This raises an IOError Just be sure of the error that you want to raise, since some of them will do stuff like closing open file descriptors as well. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonesque interface.
OP = Original Poster -- http://mail.python.org/mailman/listinfo/python-list
Re: How should multiple (related) projects be arranged (structured) and configured so that they can share code, have a related package structure and enable proper unittesting, and ensuring no namespac
I believe that Paddy was referencing his second point about keeping production code and test code clearly delimited, so was recommending that a version control system be used rather than the local disk structure required by python for building module packages. Although, I have found that symlinks work fine for delimiting file structure - ex.: $BASEDIR/production files $TESTDIR/test files $TESTDIR/link to $BASEDIR Using an example program that I wrote, the following directory structure snippet works for me (where 'bin' is a directory to shared modules of production code): -rw-r--r-- 1 ken users 509 2004-11-30 13:35 label.ini lrwxrwxrwx 1 ken users 9 2004-12-29 01:54 bin - ../../bin/ drwxr-xr-x 3 ken users 72 2004-12-10 16:01 data/ drwxr-xr-x 2 ken users 80 2004-12-10 16:46 disp/ drwxr-xr-x 2 ken users 48 2004-12-10 16:01 etc/ drwxr-xr-x 2 ken users 80 2004-12-10 16:27 prn/ drwxr-xr-x 2 ken users 208 2004-12-10 16:14 test/ drwxr-xr-x 2 ken users 1208 2004-12-10 17:15 label.py -- http://mail.python.org/mailman/listinfo/python-list
Re: How should multiple (related) projects be arranged (structured) and configured so that they can share code, have a related package structure and enable proper unittesting, and ensuring no namespac
Not sure about vcs - but cvs can be more fun if the hard disk dies {g}. -- http://mail.python.org/mailman/listinfo/python-list
Re: How should multiple (related) projects be arranged (structured) and configured so that they can share code, have a related package structure and enable proper unittesting, and ensuring no namespac
As to the question fail to see how version control relates to code/test separation, the original poster asked several questions, one of which was production/testing code separation. Along with the separation (so while you're testing new functionality, you don't break production files), a properly setup CVS allows you to do this by importing files from a production branch into your testing branch so you can re-use vetted code (production) in your trial code (testing) without affecting what's already out there (inadvertently breaking currently shipping code to customers). -- http://mail.python.org/mailman/listinfo/python-list
Re: indirect import of standard module
Unless you override some of os.* functions in foo, you want to import os into foo and bar separately. Python does not reimport the module a second time (create a second instance of os), it only creates a pointer to the first instance that's loaded. -- http://mail.python.org/mailman/listinfo/python-list
Re: indirect import of standard module
Actually, it does not execute the code only the first time, more accurately, it initializes the code only the first time. But you are correct, it exposes the os.* module into the current namespace so you don't have to go to convoluted lengths to get to it. -- http://mail.python.org/mailman/listinfo/python-list
Re: indirect import of standard module
Although 'namespace' may be a misnomer, module interfaces are 'exposed' to the module that imports it - it's not imported a second time into the new 'namespace'. The confusion comes about thinking that modules and classes are related. When a module is first imported, an instance is created for the module and the public interfaces/variables are exposed to the module that did the import. When another call to import the same module from somewhere else, Python recognizes that the module has already been imported, so it only creates a reference link to the new module that called import. That is why you get the same ID number for the module function calls. It's similar to classes in that Python keeps track of 'instances' of classes as well as 'instances' of modules, the 'class' instance is based upon variables which can be either the same class (think of a call to a function with a class instance as the input) or a new instance (where the same class is reused, but with different values), whereas modules are based upon executable bytecode where there is only one instance at all times during the program execution. -- http://mail.python.org/mailman/listinfo/python-list