import and global namespace
I'd like a module than I'm importing to be able to use objects in the global namespace into which it's been imported. is there a way to do that? thanks, nate -- http://mail.python.org/mailman/listinfo/python-list
python texts?
Hello everyone, Can anyone recommend python text progression from me. Assuming I have no knowledge of python which books should I progress through? I prefer published books that I can actually hold with my hands. But if there are some awesome tutorials on-line I guess I am game. At this moment I am reading Learning Python 2nd edition by O'Reilly. I am enjoying it at the moment. I intend to be done with it in a week. But not sure where it will put me in the grand scheme of programming with python. So perhaps a more direct question would be, what do I read after this book? Should I read something before this book? Should I ditch this book? Thanks, --Nate -- http://mail.python.org/mailman/listinfo/python-list
python texts?
Everyone that took their time to reply, thank you. I have a better idea of where to go after Learning Python. I still do not have a good idea of where this book will put me in the grand scheme of things, but oh well. I suppose that is something I will find out soon enough. Once again, thank you for your responses --Nate. -- http://mail.python.org/mailman/listinfo/python-list
maximum integer length?
Hey everyone, I am trying to figure out what is the largest integer I can. Lets say for 400 megabytes of memory at my disposal. I have tried a few things c = 2**100 d = 2**200 print c**d Obviously I didn't have enough memory for that, but I was able to c**3. (I think anyways, it is still trying to display the result) So I am just wondering how long an integer can be with 400 megabytes of memory. I guess this is a question of logic? each integer takes up a byte right? If I have 400 megabytes that would mean I could have a long integer with up to 419,430,400,000 integers? Really I am not sure on this one and that is why I am asking. Because it is just bugging me I am not sure how it works... I know this probably seems trivial and just a stupid question, but I find this type of stuff interesting... -- http://mail.python.org/mailman/listinfo/python-list
SendKeys for mac?
does anyone know if there is a way to inject keyboard events to a mac similar to the way SendKeys works for a windows machine? (Can you point me at it?) thanks, n -- http://mail.python.org/mailman/listinfo/python-list
mac findertools restart() does not work?
>>> import findertools >>> findertools.restart() Traceback (most recent call last): File "", line 1, in ? File "/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/plat-mac/findertools.py", line 90, in restart finder.restart() File "/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/plat-mac/lib-scriptpackages/Finder/Legacy_suite.py", line 29, in restart raise aetools.Error, aetools.decodeerror(_arguments) aetools.Error: (-1708, 'the AppleEvent was not handled by any handler', None) >>> does anyone know why findertools.restart() isn't working on my machine (see above code), is there something more I need to do? -- http://mail.python.org/mailman/listinfo/python-list
Re: replace a method in class: how?
I don't know a ton about this, but it seems to work if you use: This.update = another_update (instead of t.update = another_update) after saying This.update = another_update, if you enter This.update, it says , (it's unbound) but if you call t.update(5) it will print: another 5 -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG, C++, and Mac OS X
why are you modifying your setup.py file? can't you just run: swig -c++ -python exampleFile.i ? have you seen http://www.swig.org/tutorial.html , does it describe something like what you'd like to do? n -- http://mail.python.org/mailman/listinfo/python-list
Re: setting variables from a tuple NEWB
manstey wrote: > Hi, > > If I have a tuple like this: > > tupGlob = (('VOWELS','aeiou'),('CONS','bcdfgh')) > > is it possible to write code using tupGlob that is equivalent to: > VOWELS = 'aeiou' > CONS = ''bcdfgh' could you use a dictionary instead? i.e. >>> tupGlob = {'VOWELS':'aeiou', 'CONS':'bcdfgh'} >>> tupGlob['VOWELS'] 'aeiou' >>> tupGlob['VOWELS'] = 'aeiou AndSometimesY' >>> tupGlob['VOWELS'] 'aeiou AndSometimesY' nate -- http://mail.python.org/mailman/listinfo/python-list
Re: I thought I'd 'got' globals but...
try this: gname = 'nate' def test(): gname = 'amy' print gname test() print gname outputs: 'amy' 'nate' whereas this: gname = 'nate' def test(): global gname gname = 'amy' print gname test() print gname outputs: 'amy' 'amy' Luis M. González wrote: > Bruno Desthuilliers wrote: > > > > def doIt(name=None): > > global gname > > if name is None: > > name = gname > > else: > > gname = name > > > > Sorry for this very basic question, but I don't understand why I should > add the global into the function body before using it. > This function works even if I don't add the global. > Just to try this out, I wrote this variant: > > gname = 'Luis' > > def doIt2(name=None): > if name is None: > name = gname > return name > > print doIt2() --> returns Luis. > > So, what's the point of writing the function this way instead? > > def doIt2(name=None): > global gname > if name is None: > name = gname > return name > > > luis -- http://mail.python.org/mailman/listinfo/python-list
Re: I thought I'd 'got' globals but...
> OK, so I should include the global only if I plan to modify it. > Otherwise, I don't need to include it. Am I right? I guess you could say that's true. I'm hardly an expert so I couldn't say there aren't other potential ramifications. (anyone?) But, as a rule I would declare the global variable always because 1) it makes my intention clear 2) if I later decided to modify the global variable, I would be less likely to introduce a bug by forgetting to declare it global. -- http://mail.python.org/mailman/listinfo/python-list
Task Engine Framework?
Hello, I'm in the process of developing a task engine / workflow module for my Python application and I'm wondering if anyone knows of existing code that could be used or adapted. Since I know that's far too generic a question, let me share my goals: 1) Support long running operations (think backing up millions of files) where: - The operation can be paused (application closed) and the operation resumed later. - Individual tasks can be chained, run in parallel, or looped over (the workflow part) 2) Would like to graph each defined operation (task A starts task B with parameters... ) for documenting algorithms in Software Design Document 3) Each individual task in the operation would a self-contained class. I'd imagine implementing its action by defining a doTask() method. Hopefully that's clear. I just feel like someone must have already solved this elegantly. I greatly enjoy Python and I look forward to proving its use as a valuable language for a Masters student even though everyone thinks I should use C# :-). Thanks! -Nate Masters Student at Eastern Washington University -- http://mail.python.org/mailman/listinfo/python-list
Re: Task Engine Framework?
On Dec 7, 8:32 am, Adam Tauno Williams wrote: > On Mon, 2010-12-06 at 15:11 -0800, Nate wrote: > > Hello, > > I'm in the process of developing a task engine / workflow module for > > my Python application and I'm wondering if anyone knows of existing > > code that could be used or adapted. Since I know that's far too > > generic a question, let me share my goals: > > 1) Support long running operations (think backing up millions of > > files) where: > > - The operation can be paused (application closed) and the > > operation resumed later. > > - Individual tasks can be chained, run in parallel, or looped over > > (the workflow part) > > We have something like that in OIE (OpenGroupware Integration Engine). > <http://sourceforge.net/projects/coils/>. These things tend to turn out > to be quite specific [and thus not generic]. But if you have any > questions feel free to ask. The focus in OIE was the ability to > describe processes in BPML and facilitate process management [creating, > queuing, parking (stopping for later resume) of business / ETL tasks. > Parts of the code aren't especially elegant but it does move a fairly > large amount of data every day. > > > > > > > > > 2) Would like to graph each defined operation (task A starts task B > > with parameters... ) for documenting algorithms in Software Design > > Document > > 3) Each individual task in the operation would a self-contained > > class. I'd imagine implementing its action by defining a doTask() > > method > > Hopefully that's clear. I just feel like someone must have already > > solved this elegantly. I greatly enjoy Python and I look forward to > > proving its use as a valuable language for a Masters student even > > though everyone thinks I should use C# :-). Thank you, I'll take a look at the project. At the very least, seeing someone else's solution would be helpful. I'm trying desperately hard to keep the code simple :-) -Nate -- http://mail.python.org/mailman/listinfo/python-list
os.system vs subprocess
I get different behavior with os.system and subprocess (no surprise there I guess), but I was hoping for some clarification, namely why. If I type this directly into the command window: java -Xms128M -Xmx512M -jar gmapcreator.jar -dfile=censettings.xml > mapoutput.txt mapoutput.txt stores the output: Command line mode: input file=censettings.xml 1358 files will be created in C:\Documents and Settings\Nate\Desktop \freqanalysis\tilefiles\CENSUS1-tiles 1358 tiles created out of 1358 in 16 seconds If I execute said command with subprocess, the output is not written to mapoutput.txt - the output just appears in the command window. If I execute said command with os.system, the output is written to mapoutput.txt like I expected. In reality all I want to do is access the first two lines of the above output before the process finishes, something which I haven't been able to manage with subprocess so far. I saw that somehow I might be able to use os.read(), but this is my first attempt at working with pipes/processes, so I'm a little overwhelmed. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system vs subprocess
On Jun 21, 2:12 pm, Chris Rebert wrote: > On Sun, Jun 21, 2009 at 10:12 AM, Nate wrote: > > I get different behavior with os.system and subprocess (no surprise > > there I guess), but I was hoping for some clarification, namely why. > > > If I type this directly into the command window: > > > java -Xms128M -Xmx512M -jar gmapcreator.jar -dfile=censettings.xml > > > mapoutput.txt > > > mapoutput.txt stores the output: > > Command line mode: input file=censettings.xml > > 1358 files will be created in C:\Documents and Settings\Nate\Desktop > > \freqanalysis\tilefiles\CENSUS1-tiles > > 1358 tiles created out of 1358 in 16 seconds > > > If I execute said command with subprocess, the output is not written > > to mapoutput.txt - the output just appears in the command window. > > Show us the subprocess version of you code. People tend to not get the > parameters quite right if they're not familiar with the library. > > Cheers, > Chris > --http://blog.rebertia.com- Hide quoted text - > > - Show quoted text - Here it is: gmapcreator = subprocess.Popen("java -Xms128M -Xmx512M -jar gmapcreator.jar -dfile=censettings.xml", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system vs subprocess
On Jun 21, 3:49 pm, Christian Heimes wrote: > Nate wrote: > > gmapcreator = subprocess.Popen("java -Xms128M -Xmx512M -jar > > gmapcreator.jar -dfile=censettings.xml", stdin=subprocess.PIPE, > > stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > Try this: > > gmapcreator = subprocess.Popen( > ["java", "-Xms128M", "-Xmx512M", "-jar", "gmapcreator.jar", > "-dfile=censettings.xml"], stdin=subprocess.PIPE, > stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > out, err = gmapcreator.communicate("stdin input") > > The subprocess doesn't use the shell so you have to apply the command as > a list of strings. > > Do you really need stdin, stdout and stderr as pipes? If you aren't > carefully with the API your program can block. > > Christian Christian, Thanks for your response. Related to this talk about shells, maybe you could point me towards a resource where I could read about how windows commands are processed w/w/o shells? I guess I assumed all subprocess commands were intepreted by the same thing, cmd.exe., or perhaps the shell. I guess this also ties in with me wondering what the whole subprocess Popen instantiation encompassed (the __init__ of the subprocess.Popen class?). I don't think I need stdin, stdout, stderr as pipes, I just was faced with several options for how to capture these things and I chose subprocess.PIPE. I could also os.pipe my own pipes, or create a file descriptor in one of a couple of ways, right? I'm just unclear on which method is preferable for me. All I want to do is pull the first 2 lines from the output before gmapcreator.jar finishes. The first 2 lines of output are always the same except a few numbers. -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system vs subprocess
I ended up going with this: http://code.activestate.com/recipes/440554/ seems to feed me new lines of output atleast before the subprocess finishes, with some adjustment of the time delays. I'll guess I'll just be packing winpy into the installer. Or something. -- http://mail.python.org/mailman/listinfo/python-list
Re: Great books on Python?
On Sun, 11 Dec 2005 06:15:17 -0800, Tolga wrote: > > I am not unfamiliar to programming but a newbie in Python. Could you > recommend me (a) great book(s) to start with? Free online books or > solid books are welcome. > > Thanx in advance. O'Reilly's Learning Python Second Edition covers up to version 2.3 and presumes a bit of knowledge with C. I've found it well written with a rather low count of errors. - Nate >> -- "The optimist proclaims that we live in the best of all possible worlds, the pessimist fears this is true." -- http://mail.python.org/mailman/listinfo/python-list
Not understanding absolute_import
I've been trying to use from absolute_import and it's giving me a hell of a headache. I can't figure out what it's *supposed* to do, or maybe rather, it doesn't seem to be doing what I *think* it's supposed to be doing. For example (actual example from my code, assume all files have "from __future__ import absolute_import"): /project /common guid.py (has "class Guid") __init__.py (has "from .guid import Guid") /relate relatable.py (has "from .common import Guid" and "class Relatable(Guid)") __init__.py (has "from .relatable import Relatable") Now, this all compiles ok and if I change the imports, it does not. So obviously this is working. However, I can't figure out *why* it works. In relatable.py, shouldn't that need to be "from ..common import Guid"? from . should import stuff from the current directory, from . should import stuff from module foo in the current directory. to go up a directory, you should need to use .. but if I do that, python complains that I've gone up too many levels. So, I don't understand... if the way I have above is correct, what happens if I put a common.py in the relate directory? How would you differentiate between that and the common package? I don't understand why .common works from relatable. According to the docs and according to what seems to be common sense, it really seems like it should be ..common. -Nate -- http://mail.python.org/mailman/listinfo/python-list
Re: Why NOT only one class per file?
So, here's a view from a guy who's not a python nut and has a long history of professional programming in other languages (C++, C, C#, Java) I think you're all going about this the wrong way. There's no reason to *always* have one class per file. However, there's also no reason to have 1600 lines of code and 50 classes in one file either. You talk about the "changing file dance", but what about the "scroll for 30 seconds" dance? What about the "six different conflicts in source control because everything's in one file" dance? I think it doesn't matter how many classes and/or functions you have in one file as long as you keep files to a reasonable size. If you've ever worked on a medium to large-scale project using multiple developers and tens or hundreds of thousands of lines of code, then you know that keeping code separate in source control is highly important. If I'm working on extending one class and someone else is working on another class... it's much less of a headache if they're in separate files in source control. Then you don't have to worry about conflicts and merging. I think that's the number one benefit for short files (not necessarily just one class per file). My cutoff is around 500 lines per file. If a file goes much over that, it's really time to start looking for a way to break it up. Sure, if all your classes are 4 lines long, then by all means, stick them all in one file. But I don't think that's really any kind of valid stance to argue from. Sure, if you don't need organization, it doesn't matter what organization technique you use. But if you do need organization, it does matter. And I think one class per file is an acceptable way to go about it, especially when your classes tend to be over a couple hundred lines long. -Nate -- http://mail.python.org/mailman/listinfo/python-list
Re: Why NOT only one class per file?
On Apr 5, 10:48 am, Bruno Desthuilliers wrote: > Nate Finch a écrit : > > > So, here's a view from a guy who's not a python nut and has a long > > history of professional programming in other languages (C++, C, C#, > > Java) > > There are quite a few professional programmers here with experience on > medium to large to huge projects with different languages, you know. Sorry, I meant to go back and edit that phrase to sound less condescending. I know there are a lot of professional programmers on here, and I didn't mean to imply otherwise. It wasn't supposed to be a contrast to everyone, just introducing myself. I totally agree with you... there's a balance between too many files and files that are too large. As to the guy who writes 1000+ line classes dude, refactor some. You're trying to make the class do too much, almost by definition. We have *some* classes that big, and they're marked as "needs refactor". It's certainly not a common occurance, though. Usually they're UI classes, since they require a lot of verbose positioning of elements and hooking of events. And while people are reading this thread, let me plug my other thread, asking about absolute_import. I'd really love some help :) -Nate -- http://mail.python.org/mailman/listinfo/python-list
Re: "Plugin" architecture - how to do?
On Apr 5, 10:57 am, [EMAIL PROTECTED] wrote: > I'm making a program that consists of a main engine + plugins. Both > are in Python. My question is, how do I go about importing arbitrary > code and have it be able to use the engine's functions, classes, etc? For a true plugin architecture, you don't have the main engine calling methods on the plugin. What you do is have an API on your engine with methods the plugin can call and events it can hook into. The events are how the engine communicates state to any plugins, without having to know who they are or what they do. Your engine has a configuration that tells it what plugins to load (which the plugins presumably modified when they installed themselves) or otherwise has some standard way that the engine can figure out what plugins need to be loaded. Now granted, I don't specifically know how to do this via python.. but, maybe what I've said will send you in the right direction. -Nate -- http://mail.python.org/mailman/listinfo/python-list
Re: Not understanding absolute_import
On Apr 5, 8:33 am, "Nate Finch" <[EMAIL PROTECTED]> wrote: > I've been trying to use fromabsolute_importand it's giving me a hell > of a headache. I can't figure out what it's *supposed* to do, or > maybe rather, it doesn't seem to be doing what I *think* it's supposed > to be doing. No one? Is this too simple a question, or is it just that no one is using this? -Nate -- http://mail.python.org/mailman/listinfo/python-list