Re: [Tutor] global is bad but ...
Alan/Jim: It's good to hear some pragmatic advice. This particular module has 8 small functions that share common data (structures, primarily in arrays and vectors). I tried passing array_G as a parameter but that doesn't work because everything in the function remains local and I cannot get back the altered data (unless you know better?). The 'global' route works a treat so far. Dinesh ... Date: Tue, 13 Nov 2007 23:11:49 - From: "Alan Gauld" <[EMAIL PROTECTED]> Subject: Re: [Tutor] global is bad but ... To: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original "Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote > Consider a data structure (say, an array) that is operated > on by a bunch of functions eg. > > def function_A > global array_G > def function_B > global array_G > etc... > On the other hand, wiser heads say that the use of 'global' > is bad and that reworking the code into classes and objects > is better. Rather than answer your question directly can I ask, do you know *why* wiser heads say global is bad? What problems does using global introduce? What problems does it solve? > What do you think and suggest? I think it's better to understand issues and make informed choices rather than following the rules of others. I suggest you consider whether global is bad in this case and what other solutions might be used instead. Then make an informed choice. If, having researched the subject you don't understand why global is (sometimes) bad ask for more info here. HTH (a little), -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [wxPython-users] Executing a python script in WxPython
"Varsha Purohit" <[EMAIL PROTECTED]> wrote > I have an application where i need to run a python script from > wxpython gui. I am calling the script from the button click event. > And > the moment button is pressed the python script should be executed. This comes up from time to time and is usually a bad idea. Is there a reason why you cannot import the script as a module and then call a function (or functions) within the script instead of executing the script? That is a much safer and more flexible process. However, if that is impossible you can use subprocess module to execute any external program including python, so simply call that fom your event handler. If you are having difficulties post some sample code and we can give more specific help. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [wxPython-users] Executing a python script in WxPython
Thanks for the help its working now !!! On Nov 13, 2007 7:34 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > Varsha Purohit wrote: > > Hello, > > I have an application where i need to run a python script from > > wxpython gui. I am calling the script from the button click event. And > > the moment button is pressed the python script should be executed. > > If you can import the script and call the required function that is the > simplest approach. If you have to run the script as from the command > line then use os.system or subprocess.Popen. > > Kent > > > > thanks, > > Varsha Purohit, > > Graduate Student > > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > > -- Varsha Purohit, Graduate Student ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [wxPython-users] Executing a python script in WxPython
Varsha Purohit wrote: > Hello, > I have an application where i need to run a python script from > wxpython gui. I am calling the script from the button click event. And > the moment button is pressed the python script should be executed. If you can import the script and call the required function that is the simplest approach. If you have to run the script as from the command line then use os.system or subprocess.Popen. Kent > > thanks, > Varsha Purohit, > Graduate Student > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global is bad but ...
>> okay, i tried. so why are globals bad and what problems >> do they solve? The biggest complaint I have with the original example is that you've writen code to "do stuff" with array G, yet that code cannot directly be used to do the same stuff to some other array. In this sense, the code is not reusable. If it accepted G as a parameter, then it would be more general. The main advantage of globals is convenience (for example, if all you care about is getting this particular program working as soon as possible). With regard, Michael ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Maya anyone?
Da'Nivek wrote: > Hey there, > > I'm trying to learn python to use in Maya > Would it be appropriate to post a question here? You can certainly post a question...if it is too Maya-specific you may have better luck on a Maya list. We are good at Python, maybe not so good at Maya. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global is bad but ...
jim stockford wrote: > okay, i tried. so why are globals bad and what problems > do they solve? Wikipedia has a decent list: http://en.wikipedia.org/wiki/Global_variable Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] [wxPython-users] Executing a python script in WxPython
Hello, I have an application where i need to run a python script from wxpython gui. I am calling the script from the button click event. And the moment button is pressed the python script should be executed. thanks, Varsha Purohit, Graduate Student ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global is bad but ...
> okay, i tried. so why are globals bad and what problems > do they solve? now, my OS theory may be a bit rusty -- pls correct me where i'm wrong, but from what i recall, one reason they're bad is because they take up "unneeded" amount of memory. in a traditional stack model -- think C, assembly, and how binaries are loaded into the OS for execution: you have the TEXT section, which consists of the executable code, the DATA section (sometimes divided up into 2 separate areas, for zero- and nonzero-initialized/BSS data) for static variables, global variables, etc., and the STACK and HEAP, as in this diagram (drawn upside-down): http://www.informit.com/content/images/chap3_0131429647/elementLinks/03fig01.jpg the STACK is for tracking function calls (plus local variables including parameters) while all dynamically-allocated memory comes from the HEAP. by increasing the size of your DATA section for globals, it reduces the overall number of stack frames (function calls) you can chain together, and likewise, you reduce the total amount of memory that can be dynamically-allocated. the STACK grows upward while the HEAP grows downward, and memory issues occur when the twain meet. if you have tons of globals, it increases the chance of these types of collisions. this GDB tutorial page is also useful in understanding these concepts: http://www.dirac.org/linux/gdb/02a-Memory_Layout_And_The_Stack.php the way it relates to Python is that Python is (of course) written in C, and unless you're using the Stackless version of Python, each Python function call results in one Python stack frame which results in one C stack frame. hope this helps! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] NumPy Question - numpy.put in multi-dimensional array
Thank you. That works great! On Nov 13, 2007 7:18 PM, Eike Welk <[EMAIL PROTECTED]> wrote: > Hello Bryan! > > On Wednesday 14 November 2007 00:18, Bryan Fodness wrote: > > I see how to do it in a one-dimenstional array, but do not know the > > syntax for the multi-dimensional case. > > > > >from numpy import * > > > > a = zeros((60,40), int) > > > > fields = {} > > field = 10 > > fields[field] = '30A', 5 > > > > iy = int(fields[field][1]) > > ix = int(fields[field][0].rstrip('AB')) > > > > for j in range(iy): > > put(a,[39 - j],[1]) > Should be maybe: > a[0, 39 - j] = 1 > > > > > Can someone help me figure out how I would do it for multiple rows? > > > > I thought, > > > > for i in range(ix): > >for j in range(iy): > > put(a,[i][39-j],[1]) > change to: > a[i, 39-j] = 1 > > You could replace the nested for loops by the following code: > a[:ix, :iy:-1] = 1 > > I think you shouldn't use put(...) in your code. It is a fairly > specialized function. > > More information: > http://www.scipy.org/Numpy_Example_List_With_Doc#head-5202db3259f69441c695ab0efc0cdf45341829fc > > Regards, > Eike > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] NumPy Question - numpy.put in multi-dimensional array
Hello Bryan! On Wednesday 14 November 2007 00:18, Bryan Fodness wrote: > I see how to do it in a one-dimenstional array, but do not know the > syntax for the multi-dimensional case. > > >from numpy import * > > a = zeros((60,40), int) > > fields = {} > field = 10 > fields[field] = '30A', 5 > > iy = int(fields[field][1]) > ix = int(fields[field][0].rstrip('AB')) > > for j in range(iy): > put(a,[39 - j],[1]) Should be maybe: a[0, 39 - j] = 1 > > Can someone help me figure out how I would do it for multiple rows? > > I thought, > > for i in range(ix): >for j in range(iy): > put(a,[i][39-j],[1]) change to: a[i, 39-j] = 1 You could replace the nested for loops by the following code: a[:ix, :iy:-1] = 1 I think you shouldn't use put(...) in your code. It is a fairly specialized function. More information: http://www.scipy.org/Numpy_Example_List_With_Doc#head-5202db3259f69441c695ab0efc0cdf45341829fc Regards, Eike ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global is bad but ...
On Nov 13, 2007, at 3:11 PM, Alan Gauld wrote: > Rather than answer your question directly can I ask, do > you know *why* wiser heads say global is bad? What > problems does using global introduce? What problems > does it solve? i'll try: globals are good because they provide common data to one's entire program without issues of scope. globals are bad because one can design (or just allow to happen) software in which globals are changed by different entities within the program without coordination. the classic: globflag = True proc_1 checks globflag and starts to perform accordingly proc_2 changes globflag to False for some good reason before proc_1 has finished, and enough before so that there's trouble. how to get the good without the bad? in a small program, be a disciplined coder. in a large program, wrap the globals in some function wrapper that doesn't easily allow changes to the global data. in the above case, write some kind of not_yet code to keep proc_2 from changing globflag until after proc_1 is finished. okay, i tried. so why are globals bad and what problems do they solve? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error: 'module' object is not callable
Hi, Thanks. I have used the following code http://www.ipsl.jussieu.fr/~jmesce/Taylor_diagram/Miscelaneous/model_vs_data_comp_stat.py ajay --- Alan Gauld <[EMAIL PROTECTED]> wrote: > "Ajaya Mohan R. S." <[EMAIL PROTECTED]> wrote > > > I am trying to run a code for plotting Taylor > diagram, > > ending up with the following errors. How do I fix > > these errors? Help appreciated. > > Without any sight of the code that caused them its > hard > to give sensible answers. We can only suggest > general > options: > > > Error: 'module' object is not callable > > Suggests that you are trying to call a module! > Do you have a pair of parens after a module name > (or a reference to a module name) For example > > import foo > > # do some stuff > > bar = foo > # more stuff > bar() # error here coz bar refers to module foo > > > > Traceback (most recent call last): > > File "model_vs_data_comp_stat.py", line 1471, in > ? > >normalize_sign_option=normalize_sign_option, > > scaling_factor=scaling_factor) > > This looks like the end of a function/method call > but > we can't see the beginning... > > > > File "model_vs_data_comp_stat.py", line 1197, in > > model_vs_data_comp_stat > >all_model_output = MV.sort (all_model_output, > 0) > > > ValueError: sort axis argument out of bounds > > So where is the axis value derived? > > Other than that I doubt we can help without > visibility > of some code. > > HTH, > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.freenetpages.co.uk/hp/alan.gauld > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Want ideas for reducing your carbon footprint? Visit Yahoo! For Good http://uk.promotions.yahoo.com/forgood/environment.html ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error: 'module' object is not callable
"Ajaya Mohan R. S." <[EMAIL PROTECTED]> wrote > I am trying to run a code for plotting Taylor diagram, > ending up with the following errors. How do I fix > these errors? Help appreciated. Without any sight of the code that caused them its hard to give sensible answers. We can only suggest general options: > Error: 'module' object is not callable Suggests that you are trying to call a module! Do you have a pair of parens after a module name (or a reference to a module name) For example import foo # do some stuff bar = foo # more stuff bar() # error here coz bar refers to module foo > Traceback (most recent call last): > File "model_vs_data_comp_stat.py", line 1471, in ? >normalize_sign_option=normalize_sign_option, > scaling_factor=scaling_factor) This looks like the end of a function/method call but we can't see the beginning... > File "model_vs_data_comp_stat.py", line 1197, in > model_vs_data_comp_stat >all_model_output = MV.sort (all_model_output, 0) > ValueError: sort axis argument out of bounds So where is the axis value derived? Other than that I doubt we can help without visibility of some code. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] NumPy Question - numpy.put in multi-dimensional array
I see how to do it in a one-dimenstional array, but do not know the syntax for the multi-dimensional case. from numpy import * a = zeros((60,40), int) fields = {} field = 10 fields[field] = '30A', 5 iy = int(fields[field][1]) ix = int(fields[field][0].rstrip('AB')) for j in range(iy): put(a,[39 - j],[1]) Can someone help me figure out how I would do it for multiple rows? I thought, for i in range(ix): for j in range(iy): put(a,[i][39-j],[1]) but, Traceback (most recent call last): put(a,[i][39 - j],[1]) IndexError: list index out of range ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [tutor] File format conversion
Hello Alan, It is a file having colour data grid.. just like any simple ascii file and i need to manipulate the numbers with colours. But at this stage i am not much bothered with colurs i can associate it with simple RGB value for all different numbers. ex. of such simple file can be like this.. ncols 4 nrows 4 xllcorner 392800 yllcorner 5376340 cellsize 55 NODATA_value - 9 3 7 3 8 3 2 7 3 2 1 3 3 7 3 2 and i need to associate each pixel of the image with this data in the ascii... Did that help ?? thanks, Varsha On Nov 12, 2007 1:06 AM, Alan Gauld <[EMAIL PROTECTED]> wrote: > > "Varsha Purohit" <[EMAIL PROTECTED]> wrote > > > In one application i want to convert format of ascii file to > > binary file. > > That depends entirely on what the ASCII file contains. > Is it a comma separated list of RGB values? Or is it > a uuencode of the binary data? Or something else... > > > And using that binary file in a function of PIL i can > > convert it to an image file. > > Depending on the formatting you may not need PIL, > but it all depends on what the ASCII contains. > > > So i wanted to know how to convert the > > file format in python... is it possible by Numpy ?? > > You may only need one of the encode/decode libraries > for something like uuencoding or maybe the struct module > will do if its just raw bitmap data. > > > other alternative to convert an ascii into an bitmap image directly > > in > > PIL without Numpy?? > > Yes you can always do it manually but it all depends > on the format of the data. > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.freenetpages.co.uk/hp/alan.gauld > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global is bad but ...
"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote > Consider a data structure (say, an array) that is operated > on by a bunch of functions eg. > > def function_A > global array_G > def function_B > global array_G > etc... > On the other hand, wiser heads say that the use of 'global' > is bad and that reworking the code into classes and objects > is better. Rather than answer your question directly can I ask, do you know *why* wiser heads say global is bad? What problems does using global introduce? What problems does it solve? > What do you think and suggest? I think it's better to understand issues and make informed choices rather than following the rules of others. I suggest you consider whether global is bad in this case and what other solutions might be used instead. Then make an informed choice. If, having researched the subject you don't understand why global is (sometimes) bad ask for more info here. HTH (a little), -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Maya anyone?
Hey there, I'm trying to learn python to use in Maya Would it be appropriate to post a question here? thanks Nivek 3D Artist Kevin Nield http://www.kevinnield.com AIM: nanoennui mobile: 773 551 4678 Always have my latest info Want a signature like this? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] subprocess help, nohup
Hello, I've written a script which conducts several subprocess calls and then ultimately calls a shell script which runs even more programs... my script is using subprocess to execute a few sed calls, and then execute the script. I'm getting strange behavior: Here's a snippet of my script (any general comments are also welcome): if RUNS[k][3]==1: #model run complete, run is a DICT compWebPages=self.getCompletedWeb() #returns a DICT, which RUNS[k][0] COULD be a key if RUNS[k][0] not in compWebPages.keys(): runFile='make_'+RUNS[k][0] cmd = """sed -e 's/RUNmin=[0-9][0-9]*/RUNmin=%s/g' %s > jnk""" % (k,'make_wwwpages'); subprocess.call(cmd,shell=True) cmd = """cat jnk | sed -e 's/RUNmax=[0-9][0-9]*/RUNmax=%s/g' > %s""" % (k,runFile); subprocess.call(cmd,shell=True); subprocess.call('rm jnk',shell=True); os.chmod(runFile,0744) cmd="""./%s""" % (runFile) print "Starting %s" % (runFile) #subprocess.call(cmd,shell=True) q=raw_input('continue?'); print "Done with: %s" % (RUNS[k][0]) cmd="""rm %s""" % (runFile); subprocess.call(cmd,shell=True) You'll notice, the last subprocess call is commented out. Right now I'm just getting to that point to make sure everything is working. So, it seems to work, but I'm not sure how to get it to work if I change the command to nohup. I still want python to wait for it to return, in fact, I would like to set the python job running in the background as well... so what I'm looking at doing is: % nohup myControl.py ---> which will make several subprocess.call(s) including some that should be 'nohupped' as well... Suggestions on the syntax of how to do this? Thanks! -- Configuration `` Plone 2.5.3-final, CMF-1.6.4, Zope (Zope 2.9.7-final, python 2.4.4, linux2), Five 1.4.1, Python 2.4.4 (#1, Jul 3 2007, 22:58:17) [GCC 4.1.1 20070105 (Red Hat 4.1.1-51)], PIL 1.1.6 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Error: 'module' object is not callable
Hi, I am trying to run a code for plotting Taylor diagram, ending up with the following errors. How do I fix these errors? Help appreciated. best, Ajay Read observation data... Read 'mri_cgcm2_3_2a' model output... Compute comparison statistics... Error treating model: mri_cgcm2_3_2a Error: 'module' object is not callable Model: mri_cgcm2_3_2a ignored Traceback (most recent call last): File "model_vs_data_comp_stat.py", line 1471, in ? normalize_sign_option=normalize_sign_option, scaling_factor=scaling_factor) File "model_vs_data_comp_stat.py", line 1197, in model_vs_data_comp_stat all_model_output = MV.sort (all_model_output, 0) File "/usr/local/cdat-4.1.2/lib/python2.4/site-packages/cdms/MV.py", line 310, in sort maresult = MA.sort(a, axis) File "/usr/local/cdat-4.1.2/lib/python2.4/site-packages/Numeric/MA/MA.py", line 2029, in sort s = Numeric.sort(d, axis) File "/usr/local/cdat-4.1.2/lib/python2.4/site-packages/Numeric/Numeric.py", line 257, in sort raise ValueError, "sort axis argument out of bounds" ValueError: sort axis argument out of bounds ___ Yahoo! Answers - Got a question? Someone out there knows the answer. Try it now. http://uk.answers.yahoo.com/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] NNTP Client
On Nov 13, 2007 4:01 PM, Stephen Nelson-Smith <[EMAIL PROTECTED]> wrote: > >>> server = NNTP('news.gmane.org') > > What's wrong with that then? server, apparently:>>> s.group("gmane.discuss") ('211 11102 10 11329 gmane.discuss', '11102', '10', '11329', 'gmane.discuss') >>> server.group("gmane.discuss") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/nntplib.py", line 346, in group resp = self.shortcmd('GROUP ' + name) File "/usr/lib/python2.5/nntplib.py", line 259, in shortcmd self.putcmd(line) File "/usr/lib/python2.5/nntplib.py", line 199, in putcmd self.putline(line) File "/usr/lib/python2.5/nntplib.py", line 194, in putline self.sock.sendall(line) File "", line 1, in sendall socket.error: (32, 'Broken pipe') Stupid of me. S. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global is bad but ...
Kent Johnson wrote: > Dinesh B Vadhia <[EMAIL PROTECTED]> wrote: > >> Consider a data structure (say, an array) that is operated on by a bunch of >> functions >> >> The described way is to place the statement 'global' in line 1 of each >> function. On the other hand, wiser heads say that the use of 'global' is >> bad and that reworking the code into classes and objects is better. >> >> What do you think and suggest? >> > > Yes, global is bad. > > - Pass array_G as a parameter to each function > or > - Make all three functions methods of a class with array_G as an attribute. > Global is almost always bad. Sometimes you can make a valid argument that information truly has a global context, such as a debug flag, or the parsed options that were passed from the command line. Different philosophies... > Kent > >> Dinesh >> > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global is bad but ...
Dinesh B Vadhia <[EMAIL PROTECTED]> wrote: > Consider a data structure (say, an array) that is operated on by a bunch of > functions > > The described way is to place the statement 'global' in line 1 of each > function. On the other hand, wiser heads say that the use of 'global' is bad > and that reworking the code into classes and objects is better. > > What do you think and suggest? Yes, global is bad. - Pass array_G as a parameter to each function or - Make all three functions methods of a class with array_G as an attribute. Kent > > Dinesh ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] global is bad but ...
Consider a data structure (say, an array) that is operated on by a bunch of functions eg. def function_A global array_G do stuff with array_G return def function_B global array_G do stuff with array_G return def function_C global array_G do stuff with array_G return The described way is to place the statement 'global' in line 1 of each function. On the other hand, wiser heads say that the use of 'global' is bad and that reworking the code into classes and objects is better. What do you think and suggest? Dinesh ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] NNTP Client
On Nov 13, 2007 2:13 PM, Stephen Nelson-Smith <[EMAIL PROTECTED]> wrote: > ought it to be straightforward to write a client that does this task? Well: >>> server = NNTP('news.gmane.org') >>> resp, count, first, last, name = server.group("gmane.linux.redhat.enterprise.announce") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/nntplib.py", line 346, in group resp = self.shortcmd('GROUP ' + name) File "/usr/lib/python2.5/nntplib.py", line 260, in shortcmd return self.getresp() File "/usr/lib/python2.5/nntplib.py", line 215, in getresp resp = self.getline() File "/usr/lib/python2.5/nntplib.py", line 207, in getline if not line: raise EOFError EOFError What's wrong with that then? S. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] NNTP Client
Hello all, I wish to pull all the articles for one particular newsgroup to a local machine, on a regular basis. I don't wish to read them - I will be parsing the contents programatically. In your view is it going to be best to use an 'off-the-shelf' news reader, or ought it to be straightforward to write a client that does this task? If so, any pointers would be most welcome. S. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] parsing an array
On Nov 13, 2007 7:06 PM, bob gailer <[EMAIL PROTECTED]> wrote: > Aditya Lal wrote: > > [snip] > > > for i in a[:] will make i point to the elements of the list > To be more precise: > a[:] is a copy of the list > the for statement assigns each list element in turn to i. Assign is not > exactly the same as point. > > Yup! Bob is right. I just cut-paste the example from previous mail. It should be for i in a : ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] parsing an array
Aditya Lal wrote: > [snip] > for i in a[:] will make i point to the elements of the list To be more precise: a[:] is a copy of the list the for statement assigns each list element in turn to i. Assign is not exactly the same as point. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tkinter Canvas Widget
"Johnston Jiaa" <[EMAIL PROTECTED]> wrote > methods.html>, but do not see how to get the coordinates of the > mouse > on the canvas. Any mouse event will give you the coordinates within the event data. Trapping the mouse Movment will ensure you track the current position, > Also, after I get those coordinates, which methods would be > appropriate to draw the points onto the canvas itself? There are lots of drawing methods depending on what kind of thing you want to draw. You can draw lines, arcs, ovals, rectangles etc. If you just want to draw a single point then you can use a very short line or very small filled rectangle or circle. If you can show us some sample code where you are having problems we can be of more help. -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] manipulating data
"Bryan Fodness" <[EMAIL PROTECTED]> > f = open('TEST1.MLC') > fields = {} > for line in f: > the_line = line.split() > if the_line: >if the_line[0] == 'Field': > field = int(the_line[-1]) >elif the_line[0] == 'Leaf': > fields[field] = the_line[-1] > > which, sort of works, but it overwrites each value. You need to create an empty list when you define field and you need to append top that list. See the pseudo code I sent last time... >> So we need to create an empty list entry where we >> define field and then append here, so my pseudo >> code now becomes: >> >> f = open('foo.dat') >> for line in f: >>if field == None and 'Field' in line: >> field = int(line.split()[-1]) >> fields[field] = [] >>elif 'Leaf' in line: >> fields[field].append(line.split()[-1]) >>else: f.next() >> Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor