Re: [Tutor] query result set

2010-11-08 Thread Steven D'Aprano
On Mon, Nov 08, 2010 at 05:58:36PM -0800, Shawn Matlock wrote: > I am able to successfully query a MySQL database using zxJDBC but the result > set seems odd to me. It returns the following: > > [(u'envDB', u'systest2'), (u'envDir', u'st2'), (u'envCellName', > u'Systest2Cell'), (u'envFrontEnd',

Re: [Tutor] List comprehension question

2010-11-09 Thread Steven D'Aprano
Richard D. Moores wrote: See for a speed test with n = 100,000 and 100,000 loops As a general rule, you shouldn't try to roll your own speed tests. There are various subtleties that can throw your results right out. Timing small code snippets on modern

Re: [Tutor] Columnar Transposition Cipher question

2010-11-09 Thread Steven D'Aprano
Eike Welk wrote: On Tuesday 09.11.2010 18:36:43 Stefan Behnel wrote: Steven D'Aprano, 09.11.2010 05:01: http://pypi.python.org/pypi/obfuscate Hmm - why is the Windows installer on that page called "linux-i686"? It was probably created on Linux. That would be it. >

Re: [Tutor] List comprehension question

2010-11-10 Thread Steven D'Aprano
Richard D. Moores wrote: def proper_divisors_sum(n): return sum(list(divisors(n))) - n There's no need to call list first. sum() will happily operate on any sort of iterable -- lists, sums, iterators, generators, range objects. Anything except strings, which would be pointless even if yo

Re: [Tutor] List comprehension question

2010-11-10 Thread Steven D'Aprano
Richard D. Moores wrote: On Tue, Nov 9, 2010 at 12:54, Steven D'Aprano wrote: Richard D. Moores wrote: See <http://tutoree7.pastebin.com/R82876Eg> for a speed test with n = 100,000 and 100,000 loops As a general rule, you shouldn't try to roll your own speed tests. T

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Steven D'Aprano
Serdar Tumgoren wrote: Hi folks, I'm trying to gain a deeper understanding of why it's possible to modify list elements in-place *without* replacing them. For instance, why is the below possible? Why? Because the designer of Python, Guido van Rossum, wanted it to be possible, and he designed t

Re: [Tutor] Stupid bug

2010-11-11 Thread Steven D'Aprano
Wayne Werner wrote: Including the sister bug - continually importing something and you still get the old function because you forgot to delete the .pyc file. Whoops! Er, whoops is right... I think you may have misinterpreted what you were seeing. When you import a module for the first time,

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Steven D'Aprano
Serdar Tumgoren wrote: But I think I see your point. The list object behaves the same as the objects stored inside the list. Er, surely not... the list object is a list, the objects inside the list are ints. They do not behave the same. > In other words, the list object is a reference to

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Steven D'Aprano
Serdar Tumgoren wrote: In Python, if you have x[0] = Dummy(), the list object x stores the Dummy instance itself. I think the above example gets to the source of my confusion. Clearly the instance remains accessible via x[0], but I somehow never thought of a specific list index as an obvious

Re: [Tutor] What is a "state variable"?

2010-11-11 Thread Steven D'Aprano
Walter Prins wrote: Usually however people mean that objects (instances) have state variables, even when they talk about classes. The trouble is that classes are themselves objects, and can in fact have their own stat. This is true for Python, and Ruby, but not all languages. So what is sta

Re: [Tutor] What is a "state variable"?

2010-11-11 Thread Steven D'Aprano
Emile van Sebille wrote: "A class is a container for shared state, combined with functions (methods) that operate on that state. By putting state variables into member fields, they are accessible to all the methods of the class without having to be passed as parameters." So, by his own defin

Re: [Tutor] variables question.

2010-11-11 Thread Steven D'Aprano
Jeff Honey wrote: I have a question about where variables are exposed in python. I have a monolothic script with a number of functions defined, can those functions share variables? can I instantiate them outside the function of where they are needed? do they need to be wrapped in quotes, ever?

Re: [Tutor] List comprehension question

2010-11-11 Thread Steven D'Aprano
Richard D. Moores wrote: On Wed, Nov 10, 2010 at 01:30, Steven D'Aprano wrote: P.S. don't take that as a put down -- you should be pleased that your code is around as fast as Tim Peter's code :) Nah. But where is Tim Peter's code? The timeit module was written by Ti

Re: [Tutor] List comprehension question

2010-11-12 Thread Steven D'Aprano
Richard D. Moores wrote: I find using that at the interactive prompt a bit onerous -- lots of copy and pasting. And doubly so when comparing times for 2 or more functions. Does your Python not support readline? Normally, if you press UP ARROW or DOWN ARROW, Python will cycle through the previ

Re: [Tutor] List comprehension question

2010-11-12 Thread Steven D'Aprano
Richard D. Moores wrote: OK, but why can't I do what the timeit doc suggests, only put 2 or more functions in the file, as I do here: def test(): "Stupid test function" L = [] for i in range(100): L.append(i) if __name__=='__main__':

Re: [Tutor] 'pydoc' is not recognized as an internal or external command, ...

2010-11-12 Thread Steven D'Aprano
R Johnson wrote: 'pydoc' is not recognized as an internal or external command, operable program or batch file. This means that the program "pydoc" is not installed on your computer, or is installed somewhere where the operating system (I'm guessing you're using Windows?) can't find it. Use

Re: [Tutor] Python 2.5 Problem

2010-11-12 Thread Steven D'Aprano
Patrick Forbes wrote: I was pointed towards ignoblekey/pub pyw's and couldn't figure out to work them. I was told to use Python 2.6 but couldn't find it as I was unaware it was buried in the Library and didn't know how to work Terminal. I made several boo boo's and lost the Python 2.5 that my

Re: [Tutor] Grabbing Information from txt files

2010-11-12 Thread Steven D'Aprano
Michael Stover wrote: My apologies for my last email, admittedly I was more tired that I thought as after re-reading it and the emails coming in, I found that I did not provided "proper" information. 1. I have a script that is detecting multiple various bits of information of a video file usi

Re: [Tutor] List comprehension question

2010-11-13 Thread Steven D'Aprano
Richard D. Moores wrote: On Fri, Nov 12, 2010 at 15:26, Steven D'Aprano wrote: best = t.repeat(number=1, repeat=5) print round(best, 3) t.repeat(number=1, repeat=5) is a list of the 5 times, not the best of the 5. Oops! Good catch. Sorry about that. -- S

Re: [Tutor] python at midnight

2010-11-14 Thread Steven D'Aprano
ingo wrote: [...] Questions, Is there a date time library that accepts the 24:00? mxDateTime doesn't. I don't know of any. Is there a way to set the limit 'from the outside' (subclassing???) or a simple way around? Write a wrapper function: #Untested def datetime24(*args): try:

Re: [Tutor] While Loops: Coin Flip Game

2010-11-14 Thread Steven D'Aprano
Dawn Samson wrote: I've been trying to work on this challenge for a while now and can't get it to work (either it has 100 heads or 100 tails). Unfortunately your code has been mangled in the email, but I can guess your problem: you need to set coin = random.randrange(2) each time through

Re: [Tutor] What was your strategy?

2010-11-14 Thread Steven D'Aprano
Jorge Biquez wrote: I was wondering if you can share what was the strategy you followed to master Python (Yes I know I have to work hard study and practice a lot). I started by working through the book "Learning Python" by Mark Lutz and David Ascher. I wrote lots and lots of little Python

Re: [Tutor] Math: integers to a fractional power

2010-11-15 Thread Steven D'Aprano
Matthew Denaburg wrote: -27**(1/3) -3.0 math.pow(-27, 1/3) Traceback (most recent call last): File "", line 1, in math.pow(-27, 1/3) ValueError: math domain error Is there something going on here that I am unaware of? Yes, various things. The precedence of the exponentiatio

Re: [Tutor] new to python

2010-11-18 Thread Steven D'Aprano
gary engstrom wrote: Dear Python Tutor, Being new to python I was wondering if there is a way to import exel data into pyrhon matrix/arrays so that I have some data to work with. I know R uses Rcmdr as an easy interface for excel data, which helps keep the reader engaged while learning the langu

Re: [Tutor] Tutor Digest, Vol 81, Issue 73

2010-11-19 Thread Steven D'Aprano
Wangolo Joel wrote: I NO LONGER WANT YOUR TUTORIALS; SORRY FOR THIS:: There's no need to SHOUT -- we're not deaf. You subscribed yourself to the mailing list, you can unsubscribe yourself too. Just follow the instructions shown in EVERY email: To unsubscribe or change subscription options

Re: [Tutor] Simple counter to determine frequencies of words in a document

2010-11-20 Thread Steven D'Aprano
Josep M. Fontana wrote: def countWords(a_list): words = {} for i in range(len(a_list)): item = a_list[i] count = a_list.count(item) words[item] = count return sorted(words.items(), key=lambda item: item[1], reverse=True) with open('output.txt', 'a') as token_f

Re: [Tutor] telnetlib - character hex00 missing

2010-11-22 Thread Steven D'Aprano
Joachim Roop wrote: Even though my non-python telnet-server on the other side is sending #00-bytes, they are not recognized by python's telnetlib (characters #01-#FF seem to work fine though). My C++ implementation has no problems with this. I have to use Python 3.1 on Windows. I'm guessing

Re: [Tutor] IDEs

2010-11-22 Thread Steven D'Aprano
Josep M. Fontana wrote: Don;t run your code inside the IDE except for testing. IDEs are Development Environments, they are not ideal for executing production code. Run your file from the Terminal command prompt directly. I thought the code was not run inside the IDE but it was run by Python in

Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed: aesthetics lose

2010-11-23 Thread Steven D'Aprano
Richard D. Moores wrote: I've always disliked using "if not n % 2" to test for even/odd ints because of its convoluted logic. I don't find it convoluted. It's not quite as straightforward as a hypothetical "if even(n)", but it's pretty straightforward. Perhaps you just need to get used it i

[Tutor] Unsubscribing from mailing lists

2010-11-23 Thread Steven D'Aprano
Wangolo Joel wrote: I NO LONGER WANT YOUR TUTORIAL There's no need to SHOUT. Writing in all-caps is rude. If you don't want these emails, unsubscribe yourself. Just follow the instructions given in every single email: To unsubscribe or change subscription options: http://mail.python.org/

Re: [Tutor] IDEs

2010-11-24 Thread Steven D'Aprano
Alan Gauld wrote: The basic idea in testing is to try to break your code. Try to think of every kind of evil input that could possibly come along and see if your code survives. In amongst all of that you should have a some valid values too, and know what to expect as out put. Testing is more t

Re: [Tutor] Working with interactive Python shell

2010-11-24 Thread Steven D'Aprano
Josep M. Fontana wrote: One question for Steve (or for whoever wants to answer): you say you have a terminal with two tabs (neat, I wonder whether I can get tabs as well for my terminal in OS X) and when you need to do debugging you turn to your interactive python terminal and do; import filena

Re: [Tutor] for loops when there is only one row in the result - is there an alternative?

2010-11-25 Thread Steven D'Aprano
Rance Hall wrote: Generally you have something like this: clientlist = get_clients() # where get_clients is a prepared sql statement. normally you would get the individual rows like this: for row in clientlist: do stuff which is great for a long list of results. But I'm running into is

Re: [Tutor] List Changing Order

2010-11-25 Thread Steven D'Aprano
Corey Richardson wrote: Tutors, I recall that the keys of dictionaries have arbitrary order, and may change over time. Is this true of lists? I can't find the answer from a simple Google search. Thank you! Only if you re-arrange it yourself. list.sort(), list.reverse() and random.shuffle(li

Re: [Tutor] lambda in python

2010-11-26 Thread Steven D'Aprano
john tsolox wrote: since in Java i can pass an anonymous class to a function, and this anon class has member functions that can contain a body of implementation codes having the full expression of permissible syntax (if,for,while...), my question is, after seeing various examples of lambda in p

Re: [Tutor] %T as a strftime format identifier

2010-11-27 Thread Steven D'Aprano
Terry Carroll wrote: My question: was %T ever a valid format specifier in Python? My best guess is that it was when Edna was written (the most current release is from 2006, and the docs say it needs at least Python 1.5.2, which gives you an example of its age). It seems odd that the format i

Re: [Tutor] Reload() in v3? WAS Re: IDEs

2010-11-27 Thread Steven D'Aprano
Alan Gauld wrote: import os reload(os) Traceback (most recent call last): File "", line 1, in reload(os) NameError: name 'reload' is not defined Has reload been removed in V3? Not removed, just moved. >>> import imp >>> imp.reload The reason for moving it is that reload is quite

Re: [Tutor] string case manipulation in python 3.x

2010-11-28 Thread Steven D'Aprano
Rance Hall wrote: I need to do some case manipulation that I don't see in the documented string functions. I want to make sure that user input meets a certain capitalization scheme, for example, if user input is a name, then the first letter of each word in the name is upper case, and the rest a

Re: [Tutor] A regular expression problem

2010-11-28 Thread Steven D'Aprano
Josep M. Fontana wrote: I'm trying to use regular expressions to extract strings that match certain patterns in a collection of texts. Basically these texts are edited versions of medieval manuscripts that use certain symbols to mark information that is useful for filologists. I'm interested in

Re: [Tutor] temporarily modifying sys.path

2010-11-29 Thread Steven D'Aprano
Alan Gauld wrote: "Tim Johnson" wrote Just curious, but could the imp module help you? imp.find_module I'll be darned. I never even heard of that module, but I just did an import and looked at the docs. I *will* give that a try. I think its new in Python v3... Nah, it's been around f

Re: [Tutor] How to handle exceptions raised inside a function?

2010-11-30 Thread Steven D'Aprano
Richard D. Moores wrote: Please take a look at 2 functions I just wrote to calculate the harmonic and geometric means of lists of positive numbers: . Both Hlist and Glist must contain only positive numbers, so I really need to test for this inside each func

Re: [Tutor] A regular expression problem

2010-12-01 Thread Steven D'Aprano
Josep M. Fontana wrote: [...] I guess this is because the character encoding was not specified but accented characters in the languages I'm dealing with should be treated as a-z or A-Z, shouldn't they? No. a-z means a-z. If you want the localized set of alphanumeric characters, you need \w.

Re: [Tutor] How to handle exceptions raised inside a function?

2010-12-01 Thread Steven D'Aprano
Patty wrote: This is very interesting to me - the below excerpt is something I was trying to do for one of my programs and gave up on it: A fifth approach, common in some other languages, is to return some arbitrary value, and set an error flag. The caller then has to write code like this:

Re: [Tutor] How to handle exceptions raised inside a function?

2010-12-01 Thread Steven D'Aprano
Richard D. Moores wrote: [...] def harmonic_mean(data): try: m = mean(1.0/x for x in data) except ZeroDivisionError: return 0.0 if m == 0.0: return math.copysign(float('inf'), m) return 1/m math.copysign! Didn't know about that one. But "mean"? It's not a built-

Re: [Tutor] permutations?

2010-12-01 Thread Steven D'Aprano
Alex Hall wrote: Hi all, I am wondering if there is a python package that will find permutations? What version of Python are you using? Starting from Python 2.6, the itertools module contains combinations, permutations and Cartesian product: >>> list(itertools.combinations([1,2,3], 1)) [(1

Re: [Tutor] a print puzzle

2010-12-02 Thread Steven D'Aprano
bob gailer wrote: On 12/2/2010 2:09 PM, Richard D. Moores wrote: [snip] I found nothing that helped as much as you have already. In the reference (for 2.6.2) under print statement I find: "print evaluates each expression in turn and writes the resulting object to standard output (see below

Re: [Tutor] Scanning a file for specific text and copying it to a new file

2010-12-02 Thread Steven D'Aprano
Ben Ganzfried wrote: I'm trying to build a program that reads in a file and copies specific sections to a new file. More specifically, every time the words "summary on" are in the original file, I want to copy the following text to the new file until I get to the words "summary off". My questio

Re: [Tutor] data structures

2010-12-02 Thread Steven D'Aprano
Knacktus wrote: Am 02.12.2010 02:51, schrieb Dana: Hello, I'm using Python to extract words from plain text files. I have a list of words. Now I would like to convert that list to a dictionary of features where the key is the word and the value the number of occurrences in a group of files base

Re: [Tutor] permutations?

2010-12-02 Thread Steven D'Aprano
Alan Gauld wrote: "Alex Hall" wrote Alright, I have it working. Now the problem is that it does not throw out reversals. I tried to do this myself with a couple loops, but I get index errors. My total list of permutations is called l. for i in range(0, len(l)): r=l[i]; r.reverse() You don'

Re: [Tutor] Newline

2010-12-03 Thread Steven D'Aprano
Ashley Blackwell wrote: Hello everybody, I'm new to the mailing list so I'm pretty sure I'll have lots of questions:) It's a very basic question I have and everybody might look at this question and say, "Wow, she reallly doesn't get it?" But oh well. Here's my question: I'm in Chapter 2 of my Py

Re: [Tutor] print problem

2010-12-03 Thread Steven D'Aprano
Hs Hs wrote: hi I have a file and it is in chunks: I want to be able to select the number that follows 'Elution: ' where the line startswith (TITLE)(say 72.958) and check if it is larger than my choice of number (say 71.4). If it is then I want to print chunk from BEGIN LINE to END LINE separa

Re: [Tutor] Need Help!

2010-12-03 Thread Steven D'Aprano
tgreen...@aol.com wrote: Hello I am totally new to python and our last assignment is that we have to create a Gui Application game similar to Hangman. The game allows the user to guess a movie title from hints and allows the player to also guess a letter in the title. Right now I just have

Re: [Tutor] Question on tkinter event binding

2010-12-04 Thread Steven D'Aprano
Evert Rol wrote: I actually find it a bit weird that a (programming?) company has a coding convention for non-English names; makes it harder if you want to hire non-Dutch speaking employees, distribute software (& code) internationally etc. I can't put my hands on the reference right now, bu

Re: [Tutor] Question on tkinter event binding

2010-12-04 Thread Steven D'Aprano
Albert-Jan Roskam wrote: Meanwhile, I tinkered a bit more with the code. I used exec() to isolate the event handler function. It works and it's better, but I think it could be still better. I'm not so fond of eval() and exec(). They have their uses, but yes, it's best to avoid them unless you

Re: [Tutor] Newline

2010-12-04 Thread Steven D'Aprano
Alex Hall wrote: On 12/4/10, Alan Gauld wrote: "Steven D'Aprano" wrote for i in (1, 2, 3): ... print(i, "spam", end="\n" if i==3 else "***") Ooooh! A new trick. I hadn't thought of using the conditional expression there but it make

Re: [Tutor] Python vs. MATLAB

2010-12-06 Thread Steven D'Aprano
Chris Fuller wrote: On Monday 06 December 2010, Jaidev Deshpande wrote: Also, wikipedia says Python is an interpreted language, what does that mean? The "interpreted" bit refers to the fact that the source code is not compiled before it is run. This is also true of Matlab. That's not comp

Re: [Tutor] Python vs. MATLAB

2010-12-06 Thread Steven D'Aprano
Joel Schwartz wrote: Chris, Can you say more about number (7) in your list? What does "pass by value" mean and what are the alternatives? Oh boy, is that a can of worms... and this is going to be a long post. You might want to go make yourself a coffee first :) Pass by whatever (also writte

Re: [Tutor] 'or' in assignment (not if statement)?

2010-12-09 Thread Steven D'Aprano
Hugo Arts wrote: Doesn't short-circuit evaluation refer specifically to the behavior where arguments are only evaluated if they need to be? It's a very useful feature, but not technically required for the "val = val or 1" behavior to work. Yes, exactly. Some languages (Pascal comes to mind) d

Re: [Tutor] 'or' in assignment (not if statement)?

2010-12-10 Thread Steven D'Aprano
ALAN GAULD wrote: Doesn't short-circuit evaluation refer specifically to the behavior where arguments are only evaluated if they need to be? It's a very useful feature, but not technically required for the "val = val or 1" behavior to work. Its essential. If Python always evaluated all par

Re: [Tutor] Writing to the terminal?

2010-12-10 Thread Steven D'Aprano
Modulok wrote: List, Forgive me if I don't describe this well, I'm new to it: [snip description of a progress bar] Here's one way: import time, sys f = sys.stdout for i in range(20): time.sleep(1) # do some work f.write('=') f.flush() # make the change visible immediately else:

Re: [Tutor] Slicing Tuples

2010-12-11 Thread Steven D'Aprano
John Russell wrote: So, my question is this, and I realize that this is *very* basic - what is going on with the last element? Why is it returning one less than I think it logically should. Am I missing something here? There is not much of an explanation in the book, but I would really like to u

Re: [Tutor] Code evaluation inside of string fails with __get_item

2010-12-11 Thread Steven D'Aprano
Tim Johnson wrote: I've never had the occasion to use assert() or any other python - shooting tools, any thoughts on that? Assertions are a great tool, but never ever, under pain of great pain, use assert for testing user input or function arguments. It's tempting to knock up a quick a

Re: [Tutor] 'or' in assignment (not if statement)?

2010-12-11 Thread Steven D'Aprano
Lie Ryan wrote: The question "Would you like Italian or Chinese for dinner" is actually a contraction of "Would you like Italian for dinner or would you like Chinese for dinner". If we ask these two questions separately to the wife, we get either "Yes or Yes", "Yes or No", "No or Yes", or "No or

Re: [Tutor] role playing game - help needed

2010-12-11 Thread Steven D'Aprano
David Hutto wrote: On Sat, Dec 11, 2010 at 11:54 AM, Lie Ryan wrote: On 12/07/10 23:37, Robert Sjöblom wrote: I've been told to use input() if I know that I'll only get integers, and raw_input() for "everything." That is a bad piece of advice. You should only use input() when you can fully tr

Re: [Tutor] 'or' in assignment (not if statement)?

2010-12-12 Thread Steven D'Aprano
Alan Gauld wrote: "Steven D'Aprano" wrote ordered a chai latte at a cafe. The waiter had no idea what that was, but must have known that "chai" means tea, and so mixed tea and coffee So now I've got to ask, what is a chai latte? I could Google it but I'm

Re: [Tutor] Writing to the terminal?

2010-12-12 Thread Steven D'Aprano
Terry Carroll wrote: import time for t in range(10,0, -1): print "%s \x0D" %t, time.sleep(1) print # get to next line print "Done!" Which operating system and terminal did you use? In my experience, using print is not satisfactory, because the print command buffers the output and doe

Re: [Tutor] The Template Pattern

2010-12-13 Thread Steven D'Aprano
Karim wrote: Hello all, I am seeking for information about the template pattern applied to python. Could you explain some implementation or anything else? it would be helpful. Design patterns are means to an end, not an end in themselves. You shouldn't say "I want to use the template patter

Re: [Tutor] Writing to the terminal?

2010-12-14 Thread Steven D'Aprano
Bill Allen wrote: Anyone know how to get WConio.putch() to properly put out a box drawing character to the screen in the while at a cmd prompt? The code page is 437, but it when I tell it to put out 188, for example, it get a 1/4 character instead of the box drawing character. My guess is tha

Re: [Tutor] Looking for a tutor to review my code and provide constructive feedback.

2010-12-17 Thread Steven D'Aprano
zicu radu wrote: Hello, How to prevent shadows a built-in in code. Please if you are kind enougth to take the time to provide feedback I would appreciate that it is constructive. The script is here: http://bpaste.net/show/12364/ Are you sure you have posted the right link? This is a functi

Re: [Tutor] os.system

2010-12-17 Thread Steven D'Aprano
jtl999 wrote: I want to pass a variable to os.system which is dir dir=raw_input ("Dir Please ") Dir Please / ok dir = / os.system ("ls" + dir) sh: ls/: No such file or directory 32512 any advice Yes -- learn to read the error messages you get. The error you get is a shell error, not a P

Re: [Tutor] unit testing - Separate methods or group tests together?

2010-12-17 Thread Steven D'Aprano
Modulok wrote: List, When you create unit tests, do you group tests for a given function together into one unit test method, or do you prefer to have separate test methods for every assert statement? Each test method should test one thing. That doesn't necessarily mean one assert, but one con

Re: [Tutor] The Template Pattern

2010-12-18 Thread Steven D'Aprano
Karim wrote: class InputStrategy( object ): """This InputStrategy class is an abstract interface to various read strategy objects. """ def read(self, filePath): """Abstract method to load into database memory an input file. @arg: filePath - string - The input file

Re: [Tutor] os.startfile

2010-12-19 Thread Steven D'Aprano
Lang Hurst wrote: I have the following in my program: try: os.startfile('current_credit.txt') except: os.system('/usr/bin/xdg-open current_credit.txt') Basically, open a file in notepad if I'm on windows, vim if on my home linux computer. It works fin

Re: [Tutor] Problem with print

2010-12-20 Thread Steven D'Aprano
David Hutto wrote: On Sun, Dec 19, 2010 at 4:33 PM, Hugo Arts wrote: On Sun, Dec 19, 2010 at 10:11 PM, Sander Sweers wrote: On 19 December 2010 21:54, jtl999 wrote: File "GettingStarted.py", line 91 print ("Lesson Two") ^ SyntaxError: invalid syntax [...] Apparently so, but I

Re: [Tutor] calling setters of superclasses

2010-12-20 Thread Steven D'Aprano
Alan Gauld wrote: "Gregory, Matthew" wrote class PositiveX(object): def __init__(self): @property def x(self): @x.setter def x(self, val): I don't use properties in Python very often (hardly ever in fact) and I've never used @setter so there may be naming requirements I'm not

Re: [Tutor] doing maths on lists

2010-12-20 Thread Steven D'Aprano
Chris Begert wrote: Bonjour I have three lists with 65 float items and would like to do the following sum: L0 = ([sum(L0A[i]*cos(L0B[i]+L0C[i]*JME) for i in range(0,64,1))]) [...] However, I always get this error: TypeError: can't multiply sequence by non-int of type 'float'

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-20 Thread Steven D'Aprano
ashish makani wrote: Goal : I am trying to parse a ginormous ( ~ 1gb) xml file. I sympathize with you. I wonder who thought that building a 1GB XML file was a good thing. Forget about using any XML parser that reads the entire file into memory. By the time that 1GB of text is read and pars

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-20 Thread Steven D'Aprano
Brett Ritter wrote: On Mon, Dec 20, 2010 at 4:19 PM, Steven D'Aprano wrote: Goal : I am trying to parse a ginormous ( ~ 1gb) xml file. I sympathize with you. I wonder who thought that building a 1GB XML file was a good thing. XML is like violence: if it isn't working, try more.

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-21 Thread Steven D'Aprano
Alan Gauld wrote: XML is a self-describing data format. It is usually used for files but can be used in data streams or in-memory strings. It's natural competitors are TLV (Tag,Lenth,Value) and CSV(Comma Seperated Value) files but neither is as rich in structure. Alternative options include AS

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-21 Thread Steven D'Aprano
Stefan Behnel wrote: David Hutto, 21.12.2010 10:29: File = string going through string code finding pieces of the string and marking the territory. I don't see 'real' optimization other than rolling your own. Reads like a Haiku. Doesn't quite fit the verse, though. From your behaviour, I

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-21 Thread Steven D'Aprano
David Hutto wrote: Establish that with fact that initiatially I didn't have a reason to be hostile, and that your comment of my kubit kaba here, and your comment on comp.python.lang about your pystats, aftger our conversation, and your reference to it not being "set in stone", wasn't a reference

Re: [Tutor] Dictionary Question

2010-12-22 Thread Steven D'Aprano
Garry Bettle wrote: Howdy all, Hope this message finds everyone well. I have dictionary of keys and a string of values. i.e. 8 Fixtures: I assume each fixture is a key, e.g. Swin, HGrn, etc. Swin1828 1844 1901 1916 1932 1948 2004 2019 2036 2052 2107 2122 HGrn1148 1204 1218 1232 12

Re: [Tutor] Problems processing accented characters in ISO-8859-1 encoded texts

2010-12-23 Thread Steven D'Aprano
Josep M. Fontana wrote: I am working with texts that are encoded as ISO-8859-1. I have included the following two lines at the beginning of my python script: !/usr/bin/env python # -*- coding: iso-8859-1 -*- If I'm not mistaken, this should tell Python that accented characters such as 'á', 'Á',

Re: [Tutor] Problems processing accented characters in ISO-8859-1 encoded texts

2010-12-23 Thread Steven D'Aprano
Josep M. Fontana wrote: Sorry! Sorry! Sorry! I just found out this question had already been answered by Steven D'Aprano in another thread! The trick was to add '\w' besides [a-zA-Z]. Hah ha! I didn't see this before I answered... I thought the question sounded famili

Re: [Tutor] Weighted Random Choice - Anyone have an efficient algorithm?

2010-12-23 Thread Steven D'Aprano
Modulok wrote: Does anyone know of an efficient way of doing a weighted random choice? (I don't even know what algorithms like this would be called.) If you google for "python weighted random choice" you will find a number of hits. Preferably, something that doesn't grow exponentially with

Re: [Tutor] Problems processing accented characters in ISO-8859-1 encoded texts

2010-12-24 Thread Steven D'Aprano
Josep M. Fontana wrote: Just one more question. You say that \w means alphanumeric, not just alpha. Is there any expression that would mean "just alpha" and (given the appropriate LOCALE setting) would match 'a' and 'ö' but not '9'? Unfortunately, I don't think there is a standard code for jus

Re: [Tutor] Java Virtual Machine Launcher Question

2010-12-26 Thread Steven D'Aprano
Apologies if you get (half of) this message twice, I'm having trouble with Thunderbird. Ben Ganzfried wrote: Happy holidays everyone! My current question relates to a broader python programming question I have and so I thought it was worth posting here. I'm trying to read a single MAGE-TAB fi

Re: [Tutor] test

2010-12-27 Thread Steven D'Aprano
Chrystal wrote: Hi guys I'll be happy if someone can help evaluate the result of this statement: for n in range (3, 20): for x in range (2, n): print (n) I tried but couldn't figure out why the loop returned such a result It would help if you told us what result you get, what result you

Re: [Tutor] Python 2.7.1 interpreter passing function pointer as function argument and Shedskin 0.7

2010-12-29 Thread Steven D'Aprano
Alan Gauld wrote: "Frank Chang" wrote I apologize for the cut and paste mangling. Is there a better method than copy-pasting for including 20 or more lines of python source code in the tutor posts? Thank you. Long listings are usually better in pastebin - where the indentation is clear

Re: [Tutor] scraping and saving in file

2010-12-29 Thread Steven D'Aprano
Tommy Kaas wrote: I have uploaded a simple table on my web page and try to scrape it and will save the result in a text file. I will separate the columns in the file with #. It works fine but besides # I also get spaces between the columns in the text file. How do I avoid that? The print comm

Re: [Tutor] Python 2.7.1 interpreter question

2010-12-29 Thread Steven D'Aprano
Frank Chang wrote: When I use the Python 2.7.1 interpreter I get the following traceback : F:\shedskin\shedskin-0.7>python automata_test2.py Traceback (most recent call last): File "automata_test2.py", line 23, in list(automata.find_all_matches('nice', 1, m)) AttributeError: 'modul

Re: [Tutor] Initialize values from a text input file

2011-01-03 Thread Steven D'Aprano
Tim Johnson wrote: I'm just have a little fun here, but I bet that comments will help further elighten me on the subtleties of python. consider the following console session: L = ['foo','bar'] locals()[L[0]] = L[1] This will not do what you think it does. In general, local variables are not

Re: [Tutor] Initialize values from a text input file

2011-01-04 Thread Steven D'Aprano
Tim Johnson wrote: consider the following console session: L = ['foo','bar'] locals()[L[0]] = L[1] [...] (2) Even if it did work, do you trust the source of the text? Taking external data provided by arbitrary untrusted users and turning it into variables is a good way to have your compute

Re: [Tutor] regex question

2011-01-04 Thread Steven D'Aprano
Dave Angel wrote: One hazard is if the string the user inputs has any regex special characters in it. If it's anything but letters and digits you probably want to escape it before combining it with your \\b strings. It is best to escape any user-input before passing it to regex regardless.

Re: [Tutor] range function and floats?

2011-01-05 Thread Steven D'Aprano
Alan Gauld wrote: ...this is more about learning how the range function and floats work than about writing a super-efficient program. Unfortunately they don't work together. range(0.1,0.5,0.1) -> [0.1,0.2,0.3,0.4] doesn't work you need to do: for n in range(1,5): use( n/10 ) There ar

Re: [Tutor] syntax error that i cant spot!

2011-01-05 Thread Steven D'Aprano
Noah Hall wrote: He has no classes in there. Therefore, there is no place it should be in this code. Please remember this is Python, and not Java nor anything else. [...] It just makes life easier. Oh the irony... talking about making life easier, who are you talking to? What about? Please

Re: [Tutor] syntax error that i cant spot!

2011-01-05 Thread Steven D'Aprano
Noah Hall wrote: Please quote enough of the previous message to establish context -- when you are replying to the message, it is fresh in your mind. When others read your reply (possibly days later like I'm doing now), the context is anything but clear and your message comes across as merely mys

Re: [Tutor] range function and floats?

2011-01-05 Thread Steven D'Aprano
Wayne Werner wrote: The decimal module allows you to get rid of those pesky floating point errors. See http://docs.python.org/library/decimal.html for more info. That's a myth. Decimal suffers from the same floating point issues as binary floats. It's quite easy to demonstrate the same sort

Re: [Tutor] range function and floats?

2011-01-05 Thread Steven D'Aprano
Wayne Werner wrote: On Wed, Jan 5, 2011 at 10:43 AM, Steven D'Aprano wrote: Wayne Werner wrote: The decimal module allows you to get rid of those pesky floating point errors. See http://docs.python.org/library/decimal.html for more info. That's a myth. Decimal suffers fro

Re: [Tutor] vim as a python editor

2011-01-07 Thread Steven D'Aprano
Alan Gauld wrote: "Paul Griffiths" wrote I've learned that: ... - re-configuring the Caps Lock to be an extra Esc saves time Huh? How do you use that? Its a new one on me. Why would two escape keys be useful? What if you want to escape the escape, so that (say) esc-C is the same as just C

<    1   2   3   4   5   6   7   8   9   10   >