Re: [Tutor] Emailing code

2012-04-06 Thread Steven D'Aprano
myles broomes wrote: This question isnt so much related to a specific program, just something im curious about. What is the best way to email code? I find that when i copy and paste it into an email, the indentation and spacing gets all messed up. Don't send HTML, because that is poison to corr

Re: [Tutor] Tkinter GUI crashing problem

2012-04-06 Thread Steven D'Aprano
myles broomes wrote: Im working the Tkinter and I'm having a problem with the GUI I made. It crashes whenever I hit the submit button. Heres my code: Define "crashes". Does it: * cause your computer to Blue Screen of Death? * lock up your computer until you Ctrl-Alt-Delete? * cause Windows t

Re: [Tutor] Opensource projects / Subversion

2012-04-08 Thread Steven D'Aprano
mjole...@gmail.com wrote: Hey everyone, I finally made my way into working on Opensource projects. I installed tortoisesvn. I included command line tools when running the installer. However when I invoke svn at command line, I get the following error: "svn: command not found" It seems like s

Re: [Tutor] Re.findall()

2012-04-12 Thread Steven D'Aprano
mjole...@gmail.com wrote: Hi everyone, I am having trouble understanding re.findall(). I've read through the documentation and looked at at some examples online, but I still don't have a clear picture. I am going through pythonchallenge.com and I am on challenge 3. I've see. The answer to the p

Re: [Tutor] Iterate Suggestion

2012-04-14 Thread Steven D'Aprano
Bod Soutar wrote: How about something like this mylist = ['serverA', 'serverB', 'serverC', 'serverD','serverE', 'serverF', 'serverG'] tempstr = "" count = 0 for item in mylist: count += 1 if count == 3: tempstr += (i + "\n") count = 0 else: tempstr += (i +

Re: [Tutor] Python Fails to Change Directory

2012-04-14 Thread Steven D'Aprano
Andrew Jahn wrote: Hi all, I am attempting to use a Python program to change into a specified directory before executing some commands. However, when I call the Python program from my Unix shell (tcsh) using a command such as "python myprogram.py" It runs without changing directory. Just to cl

Re: [Tutor] Help with regular expression

2012-04-15 Thread Steven D'Aprano
syed zaidi wrote: Dear all Can someone please tell me how to solve the following problem. I have developed a python code to extract specific information from more than 1000 files which have slightly different format. The problem I am facing is that I have to develop specific RE for each of the

Re: [Tutor] Help with regular expression

2012-04-15 Thread Steven D'Aprano
syed zaidi wrote: Dear Steve,Tutor doesn't allow attachment of huge files. I am attaching the files I am taking as input, code and the output CSV file. I hope then you would be able to help me. DOT keg files open in file viewer, you can also view them in python. The CSV file is the desired output

Re: [Tutor] static methods & class methods

2012-04-20 Thread Steven D'Aprano
Surya K wrote: I have a class, and want to use a method of it in the class itself. How can I do it? I mean, say I defined foo() , bar() methods in a class myClass. So, how can we i use foo() in bar(). class C: def foo(self): print("foo") def bar(self): self.foo()

Re: [Tutor] why gtk.Entry does not give me right answers?

2012-04-23 Thread Steven D'Aprano
Lion Chen wrote: > Hi, All, > > i am trying write a calculator, now normal calculation works ok. but if > i enter long numbers, for example 33 + 7, it gives me > "12". > > there are 18 "3"s, if the length is more than 17, the calculation will > be wrong on Wind

Re: [Tutor] Help with graphics please

2012-04-24 Thread Steven D'Aprano
On Tue, Apr 24, 2012 at 03:57:58PM +0800, Ivor Surveyor wrote: > > I request help in locating the graphics module "graphics.py" Have you tried searching for "Python programming by John Zelle graphics.py" on any of the major search engines, like Google, Yahoo or DuckDuckGo? That should always be

Re: [Tutor] running an imported function

2012-04-27 Thread Steven D'Aprano
Cranky Frankie wrote: Is there a way I can import clr.py and then run clr()? The same way you import any other module and then call a function in that module. Don't be fooled by the function having the same name as the module. import clr # import the module clr.clr() # and call the fully-

Re: [Tutor] Is there a way I can print the output of help(module)?

2012-04-27 Thread Steven D'Aprano
Joel Goldstick wrote: Its really nice how python displays help from the docstrings of modules. I'd like to save this info to a file, and I realize I've never come across how to do that. At the command prompt (not the Python interactive interpreter!), run the pydoc command: pydoc math will

Re: [Tutor] Pygame installation problems

2012-04-27 Thread Steven D'Aprano
Osemeka Osuagwu wrote: Hi, I started learning Python recently, having only very little programming experience. I installed Pygame and tried using How did you install it? What operating system are you using? import pygame to test the installation and got the following error in return; Tr

Re: [Tutor] more help with vitualenv

2012-04-27 Thread Steven D'Aprano
Ivor Surveyor wrote: As suggested I visited the site virtualenv. However I could not find the files for download and to install on my machine. Could I please ask for further guidance on how to proceed? Which site did you go to? "virtualenv" is not a site, it is a name. Precision of languag

Re: [Tutor] Python Variable Addition

2012-04-30 Thread Steven D'Aprano
Mark Lawrence wrote: On 30/04/2012 19:40, Alan Gauld wrote: But if the number of spaces is critical string formatting is better still. And better than string addition. True indeed, but which of the three versions of string formatting that I'm aware of? Any of them. -- Steven __

Re: [Tutor] question about listing variables defined since session started

2012-04-30 Thread Steven D'Aprano
Comer Duncan wrote: Hi, I have a newbie type question. Say I have started a python (or ipython) session and have done some imports and have also defined some new variables since the session started. So, I have in my current namespace a bunch of things. Suppose I want to list just those variab

Re: [Tutor] question about listing variables defined since session started

2012-04-30 Thread Steven D'Aprano
Robert Sjoblom wrote: On 30 April 2012 23:25, Comer Duncan wrote: Hi, I have a newbie type question. Say I have started a python (or ipython) session and have done some imports and have also defined some new variables since the session started. So, I have in my current namespace a bunch of t

Re: [Tutor] Imaplib Select Fails while connecting folder(**Labelname) of gmail

2012-04-30 Thread Steven D'Aprano
Anurag Maherchandani wrote: I am using imaplib module for connecting to Gmail Imap, and i am getting the below mentioned error. I am using select command to connect Labelname is **LabelName I Get this Error: resp, data = self._imap.select("**LabelName") File "/usr/lib/python2.6/imaplib

Re: [Tutor] question about listing variables defined since session started

2012-05-01 Thread Steven D'Aprano
Prasad, Ramit wrote: Steven D'Aprano wrote: Robert Sjoblom wrote: On 30 April 2012 23:25, Comer Duncan wrote: Hi, I have a newbie type question. Say I have started a python (or ipython) session and have done some imports and have also defined some new variables since the session st

Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?

2012-05-01 Thread Steven D'Aprano
Santosh Kumar wrote: Its getting complicated now. Will it effect or not? Give me one word answer with one line description. No. Either of these are fine: #! /usr/bin/env python #!/usr/bin/env python This is not a Python trick. It will work for Ruby, or Perl, or any other language with an int

Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?

2012-05-01 Thread Steven D'Aprano
Alan Gauld wrote: On 02/05/12 01:02, Santosh Kumar wrote: Its getting complicated now. Will it effect or not? Give me one word answer with one line description. impossible. It depends what OS you are on, but you didn't say. If its Windows the line makes no difference. On Windows, the prese

Re: [Tutor] IPcount = 0 when used with subprocess.call (use something to convert to integer?)

2012-05-07 Thread Steven D'Aprano
On Mon, May 07, 2012 at 08:09:55PM -0700, Rogelio wrote: > import subprocess > IPcount = subprocess.call(['wc -l file.txt | awk \'{print $1}\''], shell=True) > print "You have",IPcount,"IP addresses that are alive." > > I get the following output > > 46 > You have 0 IP addresses that are alive. >

Re: [Tutor] Prescriptive vs descriptive docstring

2012-05-11 Thread Steven D'Aprano
Kal Sze wrote: Hello, PEP 257 says that docstrings should be written in a prescriptive way (i.e. using the imperative mood) instead of a descriptive way (indicative mood). PEP 257: http://www.python.org/dev/peps/pep-0257/ For those who don't know English grammatical terms, here are some examp

Re: [Tutor] Sorting the Parts of a Dictionary into a List

2012-05-11 Thread Steven D'Aprano
Jacob Bender wrote: The total function works when it returns the strength of a neuron, but I don't think the "sorted" function is the best because, with its current configuration, it returns a type error. I have been doing python for several years now. I don't know EVERYTHING there is to know, b

Re: [Tutor] (no subject)

2012-05-12 Thread Steven D'Aprano
Keitaro Kaoru wrote: hey i keep having a problem with adding commands.. i get this error message Traceback (most recent call last): File "bot.py", line 23, in import modules.core, modules.ai, modules.dict, modules.fun, modules.kc, modules.games, modules.lulz2, modules.modding, modules.met

Re: [Tutor] threading mind set

2012-05-12 Thread Steven D'Aprano
carlo locci wrote: Hello All, I've started to study python a couple of month ago(and I truly love it :)), however I'm having some problems understanding how to modify a sequential script and make it multithreaded (I think it's because I'm not used to think in that way), No, that's because mult

Re: [Tutor] Auto-response for your message to the "Tutor" mailing list

2012-05-12 Thread Steven D'Aprano
Devin Jeanpierre wrote: This is the third time I've received a message "for those of you new to the Tutor list". When does it stop? The problem isn't getting it to stop. The problem is getting it to not start up again. I too occasionally get these "Welcome" messages, about once every twenty

Re: [Tutor] threading mind set

2012-05-13 Thread Steven D'Aprano
bob gailer wrote: On 5/12/2012 8:22 PM, Steven D'Aprano wrote: By the way, in future, please don't decorate your code with stars: I think you got stars because the code was posted in HTML and bolded. Plain text readers add the * to show emphasis. I think you have it the other way

Re: [Tutor] syntax error

2012-05-13 Thread Steven D'Aprano
Devin Jeanpierre wrote: On Sat, May 12, 2012 at 10:29 PM, bob gailer wrote: oh - and always provide a specific meaningful subject My client has no idea what thread this post came from. Is it supposed to? What's your client? I'm using Thunderbird, and it too doesn't have any idea. I see t

Re: [Tutor] threading mind set

2012-05-13 Thread Steven D'Aprano
Russel Winder wrote: Steven, On Sun, 2012-05-13 at 10:22 +1000, Steven D'Aprano wrote: carlo locci wrote: Hello All, I've started to study python a couple of month ago(and I truly love it :)), however I'm having some problems understanding how to modify a sequential scr

Re: [Tutor] table to dictionary and then analysis

2012-05-17 Thread Steven D'Aprano
On Thu, May 17, 2012 at 08:27:07AM +0100, Russel Winder wrote: > Should we be promoting use of the format method in strings rather than > the % operator? % is deprecated now. It most certainly is not. There are no plans to deprecate the string % operator any time in the foreseeable future. It m

Re: [Tutor] Installing graphics module on python 2.7

2012-05-18 Thread Steven D'Aprano
Emeka wrote: Hello All, I would like to install graphics. So that I can do this: import graphics Please help me. I tried "pip install graphics" nothing came out of it. Is this for the John Zelle book "Python Programming: An Introduction to Computer Science"? If so, did you follow the instruc

Re: [Tutor] New to Python

2012-05-18 Thread Steven D'Aprano
Hi Jeremy, Welcome to Python, but please don't send HTML email (what some programs wrongly call "Rich Text"), as it completely destroys the necessary indentation of your Python code and makes it difficult or impossible to work out what your code is supposed to be. However, I will take a wild

Re: [Tutor] Parsing data from a set of files iteratively

2012-05-18 Thread Steven D'Aprano
Spyros Charonis wrote: Dear Python community, I have a set of ~500 files which I would like to run a script on. My script extracts certain information and generates several lists with items I need. For one of these lists, I need to combine the information from all 500 files into one super-list.

Re: [Tutor] shutil.rmtree clarification

2012-05-18 Thread Steven D'Aprano
Garry Willgoose wrote: I'm trying to remove a directory that has within it a directory tree structure and files and thought the following would work (the online docs seem to suggest it will remove the underlying directory tree and included files) shutil.rmtree('test_directory') but I got bac

Re: [Tutor] While learning Py: To IDE or not to IDE?

2012-05-20 Thread Steven D'Aprano
boB Stepp wrote: Finally to the question: With the stated goals above, would it be better to invest time now at the front-end in learning a powerful IDE, Depends on the powerful IDE. Personally, I haven't found an IDE that I like since I last used THINK Pascal on Apple Mac back in the 1990s.

Re: [Tutor] While learning Py: To IDE or not to IDE?

2012-05-20 Thread Steven D'Aprano
Brian van den Broek wrote: There are three basic choice: emacs, vi or vim, and everything else. There is widespread, though not uniform, consensus that The One True Editor is one of emacs and vi. After that, the rest is flamewars. That is insanity! There is only One True EDitor, ed! It is righ

Re: [Tutor] While learning Py: To IDE or not to IDE?

2012-05-21 Thread Steven D'Aprano
On Sun, May 20, 2012 at 11:57:14PM -0600, Modulok wrote: > Learning to use a command line at first feels really clunky and primitive, but > eventually it eclipses most GUI's and IDE's in terms of speed and the tools > available. You can also ooze right into system administration without much > eff

Re: [Tutor] Is this possible and should it be done?

2012-05-21 Thread Steven D'Aprano
wolfrage8...@gmail.com wrote: All, I have had a curious idea for awhile, and was wondering the best way to implement it in Python and if it is even possible. The concept is this, a file that is actually a folder that contains multiple files (Like an Archive format). The actual files are really un

Re: [Tutor] Is this possible and should it be done?

2012-05-21 Thread Steven D'Aprano
Joel Goldstick wrote: I'm not sure if this is exactly what you are looking for, but python handles tar files (various compression formats) with this module: http://docs.python.org/library/tarfile.html. Technically, tar is not a compression format. It just combines multiple files into a single

Re: [Tutor] Using a Blackjack Chart...

2012-05-23 Thread Steven D'Aprano
Ken G. wrote: I would like to create a Python program in the manner of an using flash card format. That is, a question is asked and you can respond according and you will be notify if you are correct or incorrect. Is this supposed to be a graphical flashcard program? Or something you run at t

Re: [Tutor] Parsing data from a set of files iteratively

2012-05-27 Thread Steven D'Aprano
Spyros Charonis wrote: The problem is that the list (z_coords1) returns as an empty list. I know the code works (too large to post here) So you want us to diagnose a problem in code that we can't see? I admire your confidence in our powers of deduction. [...] Short of some intricacy with

Re: [Tutor] Concatenating Strings

2012-05-28 Thread Steven D'Aprano
On Mon, May 28, 2012 at 07:07:20PM -0700, Steve Willoughby wrote: > On 28-May-12 19:00, Jeremy Duenas wrote: > >and the both printed the same output……so why would I want to use > >‘+’ to > >add strings if there seems to be no reason too? > > Juxtaposing strings only works with constants, which ma

Re: [Tutor] Concatenating Strings

2012-05-28 Thread Steven D'Aprano
On Tue, May 29, 2012 at 03:51:21PM +1000, Steven D'Aprano wrote: > > Using + is arguably preferable when you have a choice to make, since it > > works in all cases, including constants. > > I'll argue differently: even though + works with string literals as well &

Re: [Tutor] Parsing data from a set of files iteratively

2012-05-29 Thread Steven D'Aprano
Steven D'Aprano wrote: location = '/Users/spyros/Desktop/3NY8MODELSHUMAN/HomologyModels/' zdata = [] for filename in os.listdir(location): zdata.extend(get_zcoords(filename)) Hah, that can't work. listdir returns the name of the file, but not the file's path

Re: [Tutor] Parsing data from a set of files iteratively

2012-05-30 Thread Steven D'Aprano
On Wed, May 30, 2012 at 07:00:30AM +0100, Spyros Charonis wrote: > FINAL SOLUTION: Not quite. You are making the mistake of many newbies to treat Python exceptions as a problem to be covered up and hidden, instead of as a useful source of information. To quote Chris Smith: "I find it amusi

Re: [Tutor] Parsing data from a set of files iteratively

2012-05-30 Thread Steven D'Aprano
Spyros Charonis wrote: On Wed, May 30, 2012 at 8:16 AM, Steven D'Aprano wrote: [...] There is little as painful as a program which prints "An error occurred" and then *keeps working*. What does this mean? Can I trust that the program's final result is correct? How can it be

Re: [Tutor] Masked arrays & scipy.ndimage.

2012-06-01 Thread Steven D'Aprano
Koen De Munter wrote: Dear tutors, Given an image, I want to generate another image with the mean values of the pixels in their neighbourhood, thereby ignoring some of the neighbouring pixels (e.g. the padded boundary). I hoped I could use masked arrays for that, but apparently, this does not

Re: [Tutor] Benefit/Disadvantage to storing data as dictionary vs. in a class

2012-06-01 Thread Steven D'Aprano
Adam wrote: I'm working on a class that handles multiple rooms that generate a large amount of data. Currently my class model looks something like this (more apologies for any indentation errors): In my experience, what people consider "a large amount of data" and what the computer considers

Re: [Tutor] Octal confusion, please explain why. Python 3.2

2012-06-02 Thread Steven D'Aprano
Jordan wrote: Hello, first off I am using Python 3.2 on Linux Mint 12 64-bit. I am confused as to why I can not successfully compare a variable that was created as an octal to a variable that is converted to an octal in a if statement yet print yields that they are the same octal value. Because

Re: [Tutor] Division by negative numbers [was: no subject]

2012-06-02 Thread Steven D'Aprano
Jason Barrett wrote: In python, why does 17/-10= -2? Shouldn't it be -1? Integer division with negative numbers can be done in two different ways. (1) 17/-10 gives -1, with remainder 7. Proof: -1 times -10 is 10, plus 7 gives 17. (2) 17/-10 gives -2, with remainder -3. Proof: -2 times -10

Re: [Tutor] Joining all strings in stringList into one string

2012-06-02 Thread Steven D'Aprano
Jordan wrote: #Another version might look like this: def join_strings2(string_list): final_string = '' for string in string_list: final_string += string print(final_string) return final_string Please don't do that. This risks becoming slow. REALLY slow. Painfully slow.

Re: [Tutor] How to identify clusters of similar files

2012-06-02 Thread Steven D'Aprano
Albert-Jan Roskam wrote: Hi, I want to use difflib to compare a lot (tens of thousands) of text files. I know that many files are quite similar as they are subsequent versions of the same document (a primitive kind of version control). What would be a good approach to cluster the files based on

Re: [Tutor] use the data None

2012-06-03 Thread Steven D'Aprano
Corey Richardson wrote: [snip] (I've been away from Python for a bit, one of the other tutors might correct me with better practice things, I'm rusty!) Your reply is good. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change

Re: [Tutor] error_connection_refused

2012-06-05 Thread Steven D'Aprano
BILAL Mustapha wrote: Here is the code: Unfortunately not. What you have posted contains at least two SyntaxErrors that prevents it from running: def send_data(): *print("test sending data")* s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) *s.connect((IP, PORT))* Two of those

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Steven D'Aprano
Prasad, Ramit wrote: For instance, the __iter__() method is called by the iter() built-in. It can also called by any other piece of code that needs to acquire an iterator from a generic container object. There is no list of all such pieces of code that could ever call the __iter__() method of yo

Re: [Tutor] Joining all strings in stringList into one string

2012-06-06 Thread Steven D'Aprano
Prasad, Ramit wrote: But more importantly, some years ago (Python 2.4, about 8 years ago?) the Python developers found a really neat trick that they can do to optimize string concatenation so it doesn't need to repeatedly copy characters over and over and over again. I won't go into details, but

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Steven D'Aprano
Prasad, Ramit wrote: That is, for loops first try to build an iterator by calling __iter__, and if that fails they try the sequence protocol obj[0], obj[1], obj[2], ... So...I could instead write __getitem__ for the same effect? Er, no... __getitem__ and __iter__ do very different things. __

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Steven D'Aprano
Dave wrote: I was reading some tutorial material on creating iterators. It shows the following example implementation of an iterator: class Reverse: """Iterator for looping over a sequence backwards.""" def __init__(self, data): self.data = data self.index = len(data)

Re: [Tutor] special attributes naming confusion

2012-06-09 Thread Steven D'Aprano
Alan Gauld wrote: In general someone "just learning python" doesn't need to know about special names, they just use the operations they define. The only exception being __init__() in class definitions. These methods are really only of interest to someone who wants to define their own abstract

Re: [Tutor] properties beginner M Dawson book

2012-06-10 Thread Steven D'Aprano
Nicholas Harman wrote: I have done a little programming in BlueJ Java before but I decided to try the “Python style” as explained in the chapter, using properties rather than variables and getters and setters . My main question is: When using property and setter it seems I must use “__name”

Re: [Tutor] properties beginner M Dawson book

2012-06-10 Thread Steven D'Aprano
Nicholas Harman wrote: class Television(object): #Contstructor Spelling error: Constructor. Actually, technically __init__ is not the constructor. __init__ is the initializer, as the object has already been created before __init__ is called. __new__ is the constructor, although in this

Re: [Tutor] Query - Where to put in global variables, if needed, as a good programming practice

2012-06-15 Thread Steven D'Aprano
spa...@gmail.com wrote: Hello, The point of good-bad-ness of global variables aside, if I needed to use them, which is a better place to put them. 1. In the __init__ function of a class? So they are available at the time an object is initialized or 2. In the actual function of the class where th

Re: [Tutor] getpass

2012-06-15 Thread Steven D'Aprano
Mike Nickey wrote: Hey all, I'm working on a bit of code here and I'm having an issue with getpass. In the documentation, it says it hides the text entered "Prompt the user for a password without echoing." -- http://www.python.org/doc//current/library/getpass.html However when I run it in Ecli

Re: [Tutor] python varying mulitple inheritance

2012-06-17 Thread Steven D'Aprano
ke...@kendy.org wrote: Hello I'm new to classes. And I hope the my question isn't too big. I have electronic test equipment, but thought that a boat example would be easier. Can you help me untangle my class design? My problem is basically multiple inheritance, but I want to be flexible for how

Re: [Tutor] Counting Items in a List

2012-06-20 Thread Steven D'Aprano
Oğuzhan Öğreden wrote: Hi, I have been learning Python and trying little bits of coding for a while. Recently I tried to have a paragraph and create a list of its words, then counting those words. Here is the code: [code snipped] I can't understand your code! Indentation is messed up badly. I

Re: [Tutor] Sorting tuples

2012-06-20 Thread Steven D'Aprano
Mike Nickey wrote: While i'm still not sure what lamda is or represents, I've found a solution. Unfortunately, you haven't. It's only by accident that your not-quite-solution gives the correct value for the example data. Try it with this data instead: [(1, 7), (1, 3), (3, 4, 8), (2, 2)] re

Re: [Tutor] problem in opening files

2012-06-24 Thread Steven D'Aprano
Craig Cesareo wrote: Be sure your current working directory is your desktop. import os print os.getcwd() Be careful about changing the working directory from *within* Python. While you can do so, and in the hands of somebody who knows what they're doing it is perfectly fine, there are some p

Re: [Tutor] joining selected items in list

2012-06-24 Thread Steven D'Aprano
David wrote: Dear Tutors, I have a list that I wish to reorganise into fewer list items. What happens is that some of the items belong together: not ['keine', 'Antwort'] but ['Keine Antwort']. I am not aware of any list methods that can help me here, and would thus be grateful for a hint or two

Re: [Tutor] Tkinter message box

2012-06-24 Thread Steven D'Aprano
On Sun, Jun 24, 2012 at 10:00:57PM -0400, ken wrote: > > If this belongs on another list, please let me know. I am using PYTHON 3 > and tkinter. I have been playing around with messagebox. Is there any > way I can display the value of a variable inside a message box? Of course. tkinter doesn't ca

Re: [Tutor] Tutor Digest, Vol 100, Issue 58

2012-06-25 Thread Steven D'Aprano
Alan Gauld wrote: Hi Emile, On 26/06/12 00:26, Emile van Sebille wrote: Try using the operator that checks for equality such as if w[0] == 'x': This does the same thing and works even when w is an empty string. Umm, so does startswith()? Can you clarify what you mean by the last sentence?

Re: [Tutor] Looping over histogram plots

2012-06-27 Thread Steven D'Aprano
On Wed, Jun 27, 2012 at 08:47:08AM +0100, Alan Gauld wrote: > On 27/06/12 00:32, Elaina Ann Hyde wrote: > > > Thanks for the comment, the set type is no problem for me, this is > >just a variable that I call set... and it works great for my purposes, > > It may work just now but if you ever d

Re: [Tutor] wordcount.py query

2012-06-27 Thread Steven D'Aprano
On Thu, Jun 28, 2012 at 12:59:45AM +0100, Imran Javeed wrote: > Im trying to replay the code on the python cmd line but keep getting this > error > > >>> w_count[string] = w_count[string] + 1 > > Traceback (most recent call last): > File "", line 1, in > TypeError: cannot concatenate 'str' an

Re: [Tutor] .get dicionary question (mutability??)

2012-06-29 Thread Steven D'Aprano
Albert-Jan Roskam wrote: b.get(k, []) will not return the default value [], but 'None' if k is not present in 'b'. Why? Incorrect. b.get(k, []) returns the default value [] as expected. You then call the append method on that list, which returns None, and then you assign that result (None) t

Re: [Tutor] libtiff--can't find library

2012-06-29 Thread Steven D'Aprano
R Bruce van Dover wrote: ImportError: Failed to find TIFF library. Make sure that libtiff is installed and its location is listed in PATH|LD_LIBRARY_PATH|.. Libtiff is in the 'E:\\Python27\\lib\\site-packages' directory as it's supposed to. So is, e.g., Numpy, which imports just fine. What

Re: [Tutor] Math Function and Python

2012-07-01 Thread Steven D'Aprano
On Sun, Jul 01, 2012 at 11:21:11PM -0500, Greg Nielsen wrote: > Hello Tutor, > > I'm having some trouble with a mathematical function in my code. I am > attempting to create a realistic acceleration in an object, slower to speed > up at its min and max speeds and fastest in the middle. To kee

Re: [Tutor] Returning multiple objects from a function

2012-07-03 Thread Steven D'Aprano
On Tue, Jul 03, 2012 at 07:45:53PM -0700, Alexander Q. wrote: > -Alex > > P.S. Let me know if this message is sent incorrectly (I scrolled down to > the bottom of the text box to type this, as opposed to writing the message > at the top of the text box. I am guessing this is what is meant by > "t

Re: [Tutor] Bothersome NoneType Error for a List object

2012-07-04 Thread Steven D'Aprano
Osemeka Osuagwu wrote: templist = templist.append(prime) The append method operates in place, and returns None. It doesn't return a list: py> mylist = [] py> x = mylist.append(42) py> x is None True py> mylist [42] Replace that line with just templist.append(prime) -- Steven _

Re: [Tutor] Factor Analysis

2012-07-05 Thread Steven D'Aprano
Ali Torkamani wrote: 2) Generally how would you search, to find out if there exist an efficient python package for some specific task? (Google search usually results in many hardly-related *false* positives!) Start with PyPI, also known as the CheeseShop. http://pypi.python.org/pypi It's not

Re: [Tutor] Program gets stuck after a creating a list from dictinary items!

2012-07-06 Thread Steven D'Aprano
Ali Torkamani wrote: Dear Tutors, I'm trying to write a dictionary into a csv file, in the following code FlatData is the global dictionary whose keys are datetime objects, and the values are list of dictionaries. sCommonFeatures are key's that exist in all of such 'sub'-dictionaries, and sOtherF

Re: [Tutor] Program gets stuck after a creating a list from dictinary items!

2012-07-06 Thread Steven D'Aprano
Alan Gauld wrote: On 06/07/12 22:16, Ali Torkamani wrote: have the pdb.set_trace()'s for debugging, to see what's going on inside. So what does it show? If you aren't using it get rid of it. The less distractions there are the easier it is to debug things. I find it ironic that you are s

Re: [Tutor] Program gets stuck after a creating a list from dictinary items!

2012-07-06 Thread Steven D'Aprano
Ali Torkamani wrote: I could resolve it by defining a small function: def getValue(mydict,keys): A=[]; for i in keys: A=A+[mydict[i]] return A That will be terribly, painfully inefficient for large amounts of data. Do you understand Big O notation? The above is O(N**2), c

Re: [Tutor] Program gets stuck after a creating a list from dictinary items!

2012-07-06 Thread Steven D'Aprano
Prasad, Ramit wrote: I believe that the usage of 'in ' converts it into a set (or set-like) object so probably that is the same as set(list(set())). No, certainly not. That would be terribly inefficient, since it means first iterating over blah entirely to convert it into a set, and then iter

Re: [Tutor] The Best Way to go About with Self Modifying Code/Code Generation?

2012-07-08 Thread Steven D'Aprano
Aaron Tp wrote: Hey all, I have a question on using self-modifying code/code generation in Python; namely how to do it. I know others have already said not to do this, and to be honest I was going to say that same thing, but I have changed my mind. Buggrit, this is Python, where we are all

Re: [Tutor] TypeError: not all arguments converted during string formatting

2012-07-09 Thread Steven D'Aprano
Keitaro Kaoru wrote: [...] TypeError: not all arguments converted during string formatting [...] return self.html % ca cant seem to find out whats wrong with it Try experimenting at the interactive interpreter: [steve@ando ~]$ python Python 2.6.7 (r267:88850, Mar 10 2012,

Re: [Tutor] confusion about imports

2012-07-09 Thread Steven D'Aprano
Mark Lawrence wrote: On 09/07/2012 16:56, Chris Hare wrote: So, I have to admit, imports have me really confused. I am trying to break apart a 10,000+ line single file into various files Please don't break the file up for the sake of doing it, you're writing python not java :-) Agreed, b

Re: [Tutor] Examples of "With....As Statement" in Python

2012-07-10 Thread Steven D'Aprano
James Bell wrote: I'm attempting to learn how to use the "withas" statement in python. I've read the documentation and also a few tutorials but I still cannot understand the concept. or how this is normally used. Can someone please write an example or 2 of simple ways to use the "with statem

Re: [Tutor] str object is not callable

2012-07-10 Thread Steven D'Aprano
Chris Hare wrote: def special_match(string, search=re.compile(r'[^a-zA-Z0-9\.\ \-\#\$\*\@\!\%\^\&]').search): #string = string.rstrip() return not bool(search(string)) The call to bool is redundant. Get rid of it. The not operator will automatically convert its argument into a

Re: [Tutor] str object is not callable

2012-07-10 Thread Steven D'Aprano
Chris Hare wrote: Okay - I am officially embarrassed. [...] Meh, don't beat yourself up too badly. We've all been where you are now. Sometimes I look back at my early Python code... I tell you, that's always a good antidote for a big head. -- Steven _

Re: [Tutor] Regular expressions: findall vs search

2012-07-10 Thread Steven D'Aprano
Alexander Q. wrote: My question is how does Python know to return just the part in the parentheses and not to return the "blahblah" and the "yattayattayatta", etc...? The 're.search' function returns the whole thing, and if I want just the parentheses parts, I do tuples.group(1) or tuples.group(

Re: [Tutor] Extracting the list from a string

2012-07-11 Thread Steven D'Aprano
On Wed, Jul 11, 2012 at 02:18:04PM +0530, kala Vinay wrote: > Hi all, > >say i have a string s="['a','b']" and i want to get a list object > from this string s ie l=['a','b'] The AST module contains a safe way to parse and eval literal expressions, including strings, nested lists, and bu

Re: [Tutor] Accessing a Website

2012-07-12 Thread Steven D'Aprano
Fred G wrote: With the exception of step 6, I'm not quite sure how to do this in Python. Is it very complicated to write a script that logs onto a website that requires a user name and password that I have, and then repeatedly enters names and gets their associated id's that we want? Python

Re: [Tutor] converting EBCIDIC to ASCII

2012-07-13 Thread Steven D'Aprano
Prinn, Craig wrote: I am trying to convert an EBCIDIC file to ASCII, when the records are fixed length I can convert it fine, I have some files that are coming in as variable length records, is there a way to convert the file in Python? I tried using no length but then it just reads in to a fixed

Re: [Tutor] google search

2012-07-14 Thread Steven D'Aprano
Goog Cheng wrote: Hi, all! I wanna get the number of results for a query term from google , I tried some methods , xgoogle is the commonest way but still doesn't work well (BWT i'm a beginner) , Could you give me some advice Yes. Don't assume we can read your mind and know what you are talk

Re: [Tutor] newbie Questions

2012-07-16 Thread Steven D'Aprano
Matthew Ngaha wrote: Hi all. I'm new to Python and Programming in general. I've started out with Python for beginners, and so far so good. My friend who i might add, is not a programmer but has had experience in the world of programming (i dont know how much but he claims a lot), has told me to f

Re: [Tutor] passing global variable as argument.

2012-07-16 Thread Steven D'Aprano
Bala subramanian wrote: Friends, I want to define a function that can populate an array by taking its name (which is defined globally). I defined two empty arrays as follows and a function that can populate the array. In general it is tricky to resize and populate numpy arrays in place. It is

Re: [Tutor] Why isn't my simple if elif script not working?

2012-07-18 Thread Steven D'Aprano
Alexandre Zani wrote: What you want to write is this: elif name == "John Cleese" or name == "Michael Palin": elif name in ("John Cleese", "Michael Palin"): is better. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change sub

Re: [Tutor] Why isn't my simple if elif script not working?

2012-07-18 Thread Steven D'Aprano
Alexandre Zani wrote: On Wed, Jul 18, 2012 at 6:09 AM, Steven D'Aprano wrote: Alexandre Zani wrote: What you want to write is this: elif name == "John Cleese" or name == "Michael Palin": elif name in ("John Cleese", "Michael Palin"): is bett

Re: [Tutor] writing function changeColor

2012-07-18 Thread Steven D'Aprano
Emile van Sebille wrote: On 7/18/2012 12:07 PM Aditi Pai said... Hey Emile! Thanks for the advice. I think maybe I should have combined the two parts of my email. The function is just called changeColor. I don't actually want to change the color as much as alter the color. I'm not sure there's

<    9   10   11   12   13   14   15   16   17   18   >