Re: unset TCL_LIBRARY and TK_LIBRARY

2010-04-05 Thread Dave Angel
Wolfman wrote: Hello- was hoping someone could give me a hand in permanently setting my TCL_LIBRARY and TK_LIBRARY. I downloaded Python2.6 to a ThinkPad that came installed with Python2.2, and I can not run IDLE as something automatically sets TCL_LIBRARY and TK_LIBRARY to C:\IBMTools\Python22\

Re: Simplify Python

2010-04-06 Thread Dave Angel
ja1lbr3ak wrote: I'm trying to teach myself Python, and so have been simplifying a calculator program that I wrote. The original was 77 lines for the same functionality. Problem is, I've hit a wall. Can anyone help? loop = input("Enter 1 for the calculator, 2 for the Fibonacci sequence, or somet

Re: python as pen and paper substitute

2010-04-06 Thread Dave Angel
Johan Gr wrote: Manuel Graune skrev: Thanks for your reply. The output should 1) show manually selected python code and comments (whatever I think is important), 2) show selected results (final and intermediate) and 3) *not* show python code that for someone only interested in the calculati

Re: How to read file during module import?

2010-04-10 Thread Dave Angel
Jeremy wrote: I have a module that, when loaded, reads and parses a supporting file. The supporting file contains all the data for the module and the function that reads/parses the file sets up the data structure for the module. How can I locate the file during the import statement. The suppor

Re: when should I explicitely close a file?

2010-04-13 Thread Dave Angel
gelonida wrote: Hi, I've been told, that following code snippet is not good. open("myfile","w").write(astring) , because I'm neither explicitely closing nor using the new 'with' syntax. What exactly is the impact of not closing the file explicitely (implicitley with a 'with' block)? Even w

Re: How to run program in Linux

2010-04-16 Thread Dave Angel
Jim Byrnes wrote: I am just learning Python and am new to Linux so I am probably doing something to trip myself up. I am trying to run an example GUI program that fetches a record from a database. All the files are in the same folder. The program runs but its results vary depending on how I

Re: How to run program in Linux

2010-04-16 Thread Dave Angel
Jim Byrnes wrote: Dave Angel wrote: Jim Byrnes wrote: I am just learning Python and am new to Linux so I am probably doing something to trip myself up. I am trying to run an example GUI program that fetches a record from a database. All the files are in the same folder. The program runs but

Re: Incorrect scope of list comprehension variables

2010-04-17 Thread Dave Angel
Steven D'Aprano wrote: On Fri, 16 Apr 2010 08:48:03 -0700, Aahz wrote: In article <4bb92850$0$8827$c3e8...@news.astraweb.com>, Steven D'Aprano wrote: Nevertheless, it is a common intuition that the list comp variable should *not* be exposed outside of the list comp, and that the for-l

Re: How to run program in Linux

2010-04-17 Thread Dave Angel
Jim Byrnes wrote: Dave Angel wrote: Jim Byrnes wrote: Dave Angel wrote: Jim Byrnes wrote: I am just learning Python and am new to Linux so I am probably doing something to trip myself up. I am trying to run an example GUI program that fetches a record from a database. All the files are in

Re: UnicodeEncodeError during repr()

2010-04-19 Thread Dave Angel
gb345 wrote: In "Martin v. Loewis" writes: Do I need to do something especial to get repr to work strictly with unicode? Yes, you need to switch to Python 3 :-) Or should __repr__ *always* return bytes rather than unicode? In Python 2.x: yes.

Re: dict.keys() and dict.values() are always the same order, is it?

2010-04-20 Thread Dave Angel
Menghan Zheng wrote: Hello! Is it assured the following statement is always True? If it is always True, in which version, python2.x or python3.x? a = dict() ... assert(a.values == [a[k] for k in a.keys()]) --> ? Menghan Zheng No, it's never true. The assert st

Re: deleting objects present in a list

2010-04-21 Thread Dave Angel
(For some reason you posted your response before the message you were replying to. That's called Top-posting, and is bad form on these mailing lists) Sandy wrote: Thanks for the replies. Terry, What does 'immediately' mean? I did a small test and here are the results. import psutil def tes

Re: Inline Calculation of Dictionary Values

2010-04-21 Thread Dave Angel
++imanshu wrote: Hi, Is it possible to something along these lines in python :- map = { 'key1': f(), 'key2': modify_state(); val = f(); restore_state(); val, 'key3': f(), } For 'key2' I want to store the value returned by f() but after modifying the state. Do we have something like

Re: Importing package on Windows XP

2010-04-22 Thread Dave Angel
M.-H. Z wrote: Hello dear Python hackers. I have a pretty stupid problem that I cannot solve despite all my efforts: Python cannot find my modules. I am sure the answer is obvious, but I cannot find it. The problem is simple, here is a toy example (which does not work). I have a file: --- import

Re: Difference between Popen and open() for reading a file

2010-04-22 Thread Dave Angel
J wrote: I was reading something from a code review a little while ago and saw something that's got my curiosity up... Say I had a file, foo.txt that I wanted to read from, only one time and only read. So what's the difference between this: mylist = Popen(["cat","foo.txt"], stdout=PIPE).comm

Re: Calling multiple programs with subprocess

2010-04-22 Thread Dave Angel
amit wrote: How does one go about calling multiple programs using subprocess? This is the program flow: C:\> wrenv.exe C:\> make clean .. .. The 'wrenv.exe' is necessary since it sets up the proper environment for building. How do I use subprocess to execute 'wrenv.exe' and then the 'make clea

Re: chr(i) ASCII under Python 3

2010-04-27 Thread Dave Angel
Dodo wrote: Hi all, Under python 2.6, chr() "Return a string of one character whose ASCII code is the integer i." (quoted from docs.python.org) Under python 3.1, chr() "Return the string of one character whose Unicode codepoint is the integer i." I want to convert a ASCII code back to a chara

Re: External Hashing [was Re: matching strings in a large set of strings]

2010-04-30 Thread Dave Angel
Helmut Jarausch wrote: I think one could apply an external hashing technique which would require only very few disk accesses per lookup. Unfortunately, I'm now aware of an implementation in Python. Does anybody know about a Python implementation of external hashing? Thanks, Helmut. That's wh

Re: strange interaction between open and cwd

2010-05-03 Thread Dave Angel
Baz Walter wrote: On 03/05/10 14:18, Chris Rebert wrote: Whether or not /home/baz/tmp/xxx/ exists, we know from the very structure and properties of directory paths that its parent directory is, *by definition*, /home/baz/tmp/ (just chop off everything after the second-to-last slash). I would as

Re: long int computations

2010-05-03 Thread Dave Angel
Victor Eijkhout wrote: I have two long ints, both too long to convert to float, but their ratio is something reasonable. How can I compute that? The obvious "(1.*x)/y" does not work. Victor. You don't make clear what you mean by "too long to convert to float." Do you mean can't convert exa

Re: Teaching Programming

2010-05-04 Thread Dave Angel
Ethan Furman wrote: Andre Engels wrote: On Tue, May 4, 2010 at 4:35 PM, James Mills wrote: On Wed, May 5, 2010 at 12:21 AM, Ed Keith wrote: To deal with indentation I had to 1) keep track of indentation of all chunks of code embedded in the document and indent inserted chunks to the

Re: Teaching Programming

2010-05-05 Thread Dave Angel
alex23 wrote: Ed Keith wrote: Knuth wanted the generated source to be unreadable, so people would not be tempted to edit the generated code. This is my biggest issue with Knuth's view of literate programming. If the generated source isn't readable, am I just supposed to trust it? How

Re: Where is python31.dll?

2010-05-06 Thread Dave Angel
Pietro Campesato wrote: Your windows search command? Which is how I verified the above. I looked at the folder visually. Simply using os.listdir shows there is in fact a python31.dll there: somehow it was an invisible file. This is strange since I've never touched any system folder. Thanks

Re: ctypes:Multiple library access problem

2010-05-06 Thread Dave Angel
Massi wrote: Hi everyone, in my script I need to execute multiple separated loading of the same dll library, in order to handle the internal variables with different threads. Consider the followin piece of code: lib1 = cdll.LoadLibrary("MyLib.dll")) lib2 = cdll.LoadLibrary("MyLib.dll")) lib1.v

Re: column selection

2010-05-06 Thread Dave Angel
mannu jha wrote: Hi, I have few files like this: 24 ALA helix (helix_alpha, helix2) 27 ALA helix (helix_alpha, helix2) 51 ALA helix (helix_alpha, helix4) 58 ALA helix (helix_alpha, helix5) 63 ALA helix (helix_alpha, helix5) now with this program: for line in open('1.txt'):

Re: column selection

2010-05-06 Thread Dave Angel
mannu jha wrote: I tried with this: for line in open('1.txt'): columns = line.split() print columns[0], columns[1] if not line: continue but it is showing error: nmru...@caf:~> python split.py 24 ALA Traceback (most recent call last): File "split.py", line 3, in pri

Re: Re: column selection

2010-05-07 Thread Dave Angel
Dave Angel wrote: mannu jha wrote: I tried with this: for line in open('1.txt'): columns = line.split() print columns[0], columns[1] if not line: continue but it is showing error: nmru...@caf:~> python split.py 24 ALA Traceback (most recent call last): F

Re: default argument

2010-05-11 Thread Dave Angel
Back9 wrote: On May 11, 3:20 pm, Chris Rebert wrote: On Tue, May 11, 2010 at 12:08 PM, Back9 wrote: On May 11, 3:06 pm, Back9 wrote: When i try it, it complains about undefined self. i don't know why. TIA Sorry here is the what i meant cla

Re: How to add callbacks that is the same function with different argument in Tkinter python26?

2010-05-12 Thread Dave Angel
Jean-Michel Pichavant wrote: chen zeguang wrote: code is in the end. I want to print different number when pressing different button. Yet the program outputs 8 no matter which button is pressed. I guess it's because the callback function is not established untill the button is pressed, and i ha

Re: open(False) in python3

2010-05-12 Thread Dave Angel
Giampaolo Rodolà wrote: 2010/5/12 Gabriel Genellina : open() in Python 3 does a lot of things; it's like a mix of codecs.open() + builtin open() + os.fdopen() from 2.x all merged together. It does different things depending on the type and quantity of its arguments, and even returns objects

Re: write a 20GB file

2010-05-14 Thread Dave Angel
Jackie Lee wrote: Hello there, I have a 22 GB binary file, a want to change values of specific positions. Because of the volume of the file, I doubt my code a efficient one: #! /usr/bin/env python #coding=utf-8 import sys import struct try: f=open(sys.argv[1],'rb+') except (IOError,Exc

Re: huh??? weird problem

2010-05-14 Thread Dave Angel
cerr wrote: Hi There, I got following code: start=time.time() print 'warnTimeout '+str(WarnTimeout) print 'critTimeout '+str(CritTimeout) print 'start',str(start) while wait: passed = time.time()-start print 'passed ',str(passed) if passed >= WarnTimeout: print ' Warning!' ..

Re: write a 20GB file

2010-05-15 Thread Dave Angel
Nathan Rice wrote: This is precisely the situation mmap was made for :) It has almost the same methods as a file so it should be an easy replacement. Only on a 64bit system, and I'm not sure it's even possible there in every case. On a 32bit system, it would be impossible to mmap a 20gb f

Re: joining files

2010-05-16 Thread Dave Angel
mannu jha wrote: Hi, I have few files like this: file1: 22 110.1 33 331.5 22.7 5 271.9 17.2 33.4 4 55.1 file1 has total 4 column but some of them are missing in few row. file2: 5 H 22 0 file3: 4 T 5 B 22 C 121 S in all these files first column is the main source of matching their entrie

Re: joining files

2010-05-16 Thread Dave Angel
(You forgot to include the python-list in your response. So it only went to me. Normally, you just do reply-all to the message) mannu jha wrote: On Sun, 16 May 2010 13:52:31 +0530 wrote mannu jha wrote: Hi, I have few files like this: file1: 22 110.1 33 331.5 2

Re: joining files

2010-05-17 Thread Dave Angel
mannu jha wrote: On Sun, 16 May 2010 13:52:31 +0530 wrote mannu jha wrote: Hi, I have few files like this: file1: 22 110.1 33 331.5 22.7 5 271.9 17.2 33.4 4 55.1 file1 has total 4 column but some of them are missing in few row. file2: 5 H 22

Re: another question about classes and subclassing

2010-05-18 Thread Dave Angel
Alex Hall wrote: Hi again all, More about classes. I am still looking into my battleship game, and I will have several different craft. All craft have common attribs (position, alive, and so on) but each craft may be a surface ship, submarine, or airplane. All three are craft, but a submarine can

Re: another question about classes and subclassing

2010-05-18 Thread Dave Angel
Alex Hall wrote: Okay, that makes sense. So by calling submarine(craft) I am bringing in all of craft's attribs (subclassing)? Or does calling craft's __init__ method do that instead? Is there an advantage to doing it this way, rather than just making separate classes for everything, except for m

Re: why struct.pack behave like this

2010-05-20 Thread Dave Angel
Xie&Tian wrote: Hi When I use struct to pack binary data, I found this interesting behaviour: import struct struct.pack('B', 1) '\x01' struct.pack('H', 200) '\xc8\x00' struct.pack('BH',1, 200) '\x01\x00\xc8\x00' struct.calcsize('BH') 4 Wh

Re: First script. Need some help

2010-05-27 Thread Dave Angel
ledpepper wrote: #Enter in firstname.lastname (bob.smith) #Count the amount of letters(x) and vowels(y) #Then work out if bob is > but not equal to 6 letters #If firstname is less than 6 print firstnamesurnamexy #If firstname is equal to or greater than 6 print firstnamexy #Copy result to clipboa

Re: writing numbers in binary file

2010-05-31 Thread Dave Angel
eskandari wrote: On May 31, 12:30 pm, MRAB wrote: eskandari wrote: Hi, I am a newbie in python. I have an data.pickle file which is serialized form of an "array of strings", I want to write their offsets in another binary file, so an C++ program can read and analyse them. But when I tr

Re: Diff of Text

2010-06-05 Thread Dave Angel
GZ wrote: I want a library that does unix 'diff' like function, i.e. compare two strings line by line and output the difference. Python's difflib does not work perfectly for me, because the resulting differences are pretty big. I would like an algorithm that generates the smallest differences.

Re: Which objects are expanded by double-star ** operator?

2010-06-07 Thread Dave Angel
kkumer wrote: I have to merge two dictionaries into one, and in a "shallow" way: changing items should be possible by operating either on two parents or on a new dictionary. I am open to suggestions how to do this (values are always numbers, BTW), but I tried to do it by creating a dict-like clas

Re: help me

2010-06-09 Thread Dave Angel
madhuri vio wrote: this is the code i have written ..even after changing d module name i am still getting the same error... what do they mean by an attribute error...can u explain in detail i am unable to proceed further... #!usr/bin/env python #making structured graphics using tkinter interface

Re: help me

2010-06-09 Thread Dave Angel
lled... so i was wondering if there was any other way of importing tkinter module and where am i wrong..i am stuck;( On Wed, Jun 9, 2010 at 3:03 PM, Dave Angel wrote: Two questions: 1) what version of Python ? You're using the version 3 capitalization. Might you have version 2.x of Pyt

Re: help me

2010-06-09 Thread Dave Angel
madhuri vio wrote: 1)2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] So you've got the wrong name for Tkinter. In version 2.x, you need import Tkinter 2)>>> import sys print sys.path ['', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/py

Re: help me

2010-06-09 Thread Dave Angel
You're still top-posting. Put your response either directly after the part you're responding to, or at the end. And of course, trim out the irrelevant parts (which I've been frequently criticized for failing to do) madhuri vio wrote: yea i was able to import by capitalizing t...thank u so mu

Re: Deformed Form

2010-06-11 Thread Dave Angel
Victor Subervi wrote: On Fri, Jun 11, 2010 at 12:24 PM, Stephen Hansen wrote: Sure, if you have some file that two separate scripts import, and in said file you generate some value-- as long as that value will be the same at all times, it'll appear that the two scripts are sharing some state

Re: Deformed Form

2010-06-11 Thread Dave Angel
Victor Subervi wrote: Ok. Starting over. Here is the script that "generates" the variable "new_passengers_curr_customers": Now, here's the form that *should* be able to access that variable: !/usr/bin/python import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd(

Re: Re: Deformed Form

2010-06-13 Thread Dave Angel
Victor Subervi wrote: DaveA suggested I not use the same name for my fn. as I do for my var; however, there is a difference in capitalization, and I'm trying to standardize this way. It makes it easy to recognize the difference (caps) and easy to recognize which vars go with which fns. Th

Re: logging = logging.getLogger(__name__)

2010-06-15 Thread Dave Angel
genkuro wrote: Newbie here. I may be missing something obvious, in which case, please feel free to berate and laugh at me. Here's a dubious line of code: logging = logging.getLogger(__name__) How can I refer to the original logging package "logging" after this statement is run? Specifically,

Re: Updating a module level shared dictionary

2010-06-16 Thread Dave Angel
Vishal Rana wrote: Hi, A module level dictionary 'd' and is accessed by different threads/requests in a django web application. I need to update 'd' every minute with a new data and the process takes about 5 seconds. What could be best solution where I want the users to get either the old value

Re: Deformed Form

2010-06-16 Thread Dave Angel
Victor Subervi wrote: DavidA corrects me: Since you didn't name your modules (what you persist in calling scripts), I can only guess their names from the import statements: e.g.: >from New_Passengers_Curr_Customers import New_Passengers_Curr_Customers I don't see any case differe

Re: Is this make sence? Dynamic assembler for python

2010-06-20 Thread Dave Angel
DivX wrote: On 20 lip, 12:46, Steven D'Aprano wrote: On Sun, 20 Jun 2010 03:19:48 -0700, DivX wrote: On 20 lip, 02:52, Steven D'Aprano wrote: [...] I think that mixing assembly and python is a gimmick of very little practical significance. If you really need the extra pe

Re: Is this make sence? Dynamic assembler for python

2010-06-21 Thread Dave Angel
Steven D'Aprano wrote: On Sun, 20 Jun 2010 18:21:43 -0400, Dave Angel wrote: Something's intrinsically wrong with the argument made in this thread against generating assembly code. That's exactly what happens every time you write code in C. I don't know whether

Re: Is this make sence? Dynamic assembler for python

2010-06-21 Thread Dave Angel
Steven D'Aprano wrote: On Mon, 21 Jun 2010 03:00:12 -0400, Dave Angel wrote: But the OP said of his friend: "He dynamically generates mashine code and call that from python." I took that to mean he dynamically generated machine code, not that he hired some human to do it.

Re: deduping

2010-06-21 Thread Dave Angel
dirknbr wrote: Hi I have 2 files (done and outf), and I want to chose unique elements from the 2nd column in outf which are not in done. This code works but is not efficient, can you think of a quicker way? The a=1 is just a redundant task obviously, I put it this way around because I think 'in'

Re: Second attempt WAS: From Dict to Classes yes or no and how

2010-06-22 Thread Dave Angel
Jerry Rocteur wrote: On Tue, Jun 22, 2010 at 9:32 PM, Jerry Rocteur wrote: If you were able to ask us perhaps a more specific question and describe your problem a little more concisely perhaps I (and we) might have a bit more to offer you. I have a dictionary: users[key] = {'user'

Re: Should I Learn Python or Ruby next?

2010-06-23 Thread Dave Angel
Stephen Hansen wrote: On 6/22/10 10:39 PM, Dennis Lee Bieber wrote: On Tue, 22 Jun 2010 15:55:51 -0700, Stephen Hansen declaimed the following in gmane.comp.python.general: I second Forth. Learning and using that was -- slightly painful, but Just pick up any advanced H

Re: best way to increment an IntVar?

2010-06-25 Thread Dave Angel
Alan G Isaac wrote: On 6/24/2010 1:59 AM, Dennis Lee Bieber wrote: It is NOT a numeric "variable" in Python realms. Sure, but why does it not behave more like one? It seems both obvious and desirable, so I'm guessing there is a good reason not to do it. So var+=increment can't be used be

Re: best way to increment an IntVar?

2010-06-25 Thread Dave Angel
Alan G Isaac wrote: On 6/25/2010 1:14 PM, Dave Angel wrote: the default behavior of += is to assign a new object with the new value, rather than changing the previous object. a = [] temp = a a += [2] temp [2] Alan Isaac I said "default", not "only" behavior. I susp

Re: hex question

2010-06-25 Thread Dave Angel
Sneaky Wombat wrote: Why is python turning \x0a into a \n ? In [120]: h='\x0a\xa8\x19\x0b' In [121]: h Out[121]: '\n\xa8\x19\x0b' I don't want this to happen, can I prevent it? You don't say what you do want. Currently, you have a literal that describes four characters. Were you tryin

Re: best way to increment an IntVar?

2010-06-25 Thread Dave Angel
Alan G Isaac wrote: On 6/25/2010 3:52 PM, Dave Angel wrote: I said "default", not "only" behavior. I suspect list provides an __iadd__ method to provide this ability. Integers do not, and therefore neither does the object the OP was asking about. I have no idea what &

Re: Build unordered list in HTML from a python list

2010-06-30 Thread Dave Angel
Nico Grubert wrote: Use a stack? Whenever you start a new list, push the corresponding closing tag onto a stack. Whenever your "indent level" decreases, pop the stack and write out the closing tag you get. It's straightforward to use a python list as a stack. Thanks for the tip, Kushal.

Re: Hwy doesn't len(None) return zero ?

2010-06-30 Thread Dave Angel
Stephen Hansen wrote: On 6/30/10 11:39 AM, Stef Mientki wrote: hello, I've lot of functions that returns their result in some kind of tuple / list / array, and if there is no result, these functions return None. Now I'm often what to do something if I've more than 1 element in the result. So

Re: Pool Module: iterator does not yield consistently with different chunksizes

2010-07-02 Thread Dave Angel
syockit wrote: I've been playing around with custom iterators to map into Pool. When I run the code below: def arif(arr): return arr def permutate(n): k = 0 a = list(range(6)) while k While I didn't actually try to follow all your code, I suspect your problem is that when you

Re: Opinions please -- how big should a single module grow?

2010-07-09 Thread Dave Angel
Steven D'Aprano wrote: This is a style question rather than a programming question. How large (how many KB, lines, classes, whatever unit of code you like to measure in) should a module grow before I should break it up into a package? I see that, for example, decimal.py is > 3000 lines of code

Re: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP

2010-07-09 Thread Dave Angel
Tim Roberts wrote: Christian Heimes wrote: Yeah, but then we're down to file descriptors, C library locales and such as the remaining problems. Don't forget errno! Every CRT might have its own errno thread local. I don't know how its handled on Windows but I suspect it suffers from

Re: Python scripts from DOS

2010-07-09 Thread Dave Angel
Mark Carter wrote: On my machine, I can go to a DOS shell, and type myscript.py This will cause the script to be run as a python script. So that bit works. On another machine, on which python was set up without admin privileges, if I type myscript.py it will open the "Open With" dialog box

Re: [Tutor] the ball needs a kick...

2010-07-09 Thread Dave Angel
yes But further messages had better be posted to the forum. And not top-posted. DaveA -- http://mail.python.org/mailman/listinfo/python-list

Re: python3: help with subprocess

2010-07-14 Thread Dave Angel
Alan wrote: Hi there, Module commands is gone in python3, so I am trying subprocess. So please I would appreciate if someone can tell me how to do this better: before I had: cmd = 'uname -a' out = commands.getoutput(cmd) 'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18

Re: Nested loop not working

2010-07-16 Thread Dave Angel
Johann Spies wrote: I am overlooking something stupid. I have two files: one with keywords and another with data (one record per line). I want to determine for each keyword which lines in the second file contains that keyword. The following code is not working. It loops through the second fil

Re: Easy questions from a python beginner

2010-07-23 Thread Dave Angel
Duncan Booth wrote: Consider languages where you can easily write a swap function (or any other function that updates its arguments). e.g. consider C or C#. For C your function must take pointers to the variables, so when you call swap you have to make this explicit by taking the address of

Re: Easy questions from a python beginner

2010-07-23 Thread Dave Angel
wheres pythonmonks wrote: Funny... just spent some time with timeit: I wonder why I am passing in strings if the callback overhead is so light... More funny: it looks like inline (not passed in) lambdas can cause python to be more efficient! import random d = (['A','B'][random.randint(0,1)

Re: Function closure inconsistency

2010-07-23 Thread Dave Angel
SeanMon wrote: I was playing around with Python functions returning functions and the scope rules for variables, and encountered this weird behavior that I can't figure out. Why does f1() leave x unbound, but f2() does not? def f1(): x = 0 def g(): x += 1 return x re

Re: newb

2010-07-27 Thread Dave Angel
whitey wrote: hi all. am totally new to python and was wondering if there are any newsgroups that are there specifically for beginners. i have bought a book for $2 called "learn to program using python" by alan gauld. starting to read it but it was written in 2001. presuming that the commands

Re: [Py2exe-users] how to build same executabl with and without console output

2010-07-30 Thread Dave Angel
pyt...@bdurham.com wrote: Is there any trick in adding a console window to an application, that was built as 'windows' application? I was recently wondering the same thing myself. My research indicates that its not possible to have a single Windows application that can run in both console

Re: ImportError: No module named binascii

2010-07-30 Thread Dave Angel
Dieter wrote: Hi there, I installed python 2.7 from the tar ball on python.org. the installation was pretty uneventful. However, I need to run someone elses python code and get the error message ImportError: No module named binascii Any recommendations how to correct this? Is there another tar

Re: namespaces, scoping and variables

2010-08-02 Thread Dave Angel
Chris Hare wrote: I am having a problem getting around this variable namespace thing. Consider these code bits File a.py from Tkinter import * import a1 def doAgain(): x =1.Net() x.show("Again!") root =k() root.title("test") f =rame(root,bg="Yellow") l =utton(root,text="window

Re: Trying to set a cookie within a python script

2010-08-03 Thread Dave Angel
� wrote: On 2 Αύγ, 23:57, Thomas Jollans wrote: So: tripple-check that * your file is * Python knows that * the web browser knows that Thank you! i used print ''' Content-Type: text/html; charset=F-8 / n''' and it worked. I'am still pretty c

Re: Trying to set a cookie within a python script

2010-08-03 Thread Dave Angel
¯º¿Â wrote: On 3 Αύγ, 11:10, Dave Angel wrote: a) a text editor takes keystrokes and cut/paste info and other data, and produces a stream of (unicode) characters. It then encodes each of those character into one or more bytes and saves it to a file. You have to tell Notepad

Re: Trying to set a cookie within a python script

2010-08-03 Thread Dave Angel
¯º¿Â wrote: On 3 Αύγ, 18:41, Dave Angel wrote: Different encodings equal different ways of storing the data to the media, correct? Exactly. The file is a stream of bytes, and Unicode has more than 256 possible characters. Further, even the subset of characters that *do* take one

Re: Trying to set a cookie within a python script

2010-08-03 Thread Dave Angel
MRAB wrote: Dave Angel wrote: ¯º¿Â wrote: On 3 Αύγ, 18:41, Dave Angel wrote: Different encodings equal different ways of storing the data to the media, correct? Exactly. The file is a stream of bytes, and Unicode has more than 256 possible characters. Further, even the subset of

Re: Trying to set a cookie within a python script

2010-08-04 Thread Dave Angel
¯º¿Â wrote: On 3 Αύγ, 21:00, Dave Angel wrote: A string is an object containing characters. A string literal is one of the ways you create such an object. When you create it that way, you need to make sure the compiler knows the correct encoding, by using the encoding: line at

Re: running a piece of code at specific intervals?

2010-08-04 Thread Dave Angel
Chris Hare wrote: Don't say cron : I want to have a section of my code executed at 15 minute intervals. I am using Threading.timer, but it is causing a problem sinxe I am using sqlite3 and the thread support gives me an error, which aborts part of my code. So, is there an alternative to thre

Re: easy question on parsing python: "is not None"

2010-08-05 Thread Dave Angel
Roald de Vries wrote: On Aug 5, 2010, at 5:42 PM, wheres pythonmonks wrote: How does "x is not None" make any sense? "not x is None" does make sense. I can only surmise that in this context (preceding is) "not" is not a unary right-associative operator, therefore: x is not None === IS_NOTEQ(

Re: simple renaming files program

2010-08-09 Thread Dave Angel
blur959 wrote: On Aug 9, 6:01 pm, Chris Rebert wrote: os.rename() takes paths that are absolute (or possibly relative to the cwd), not paths that are relative to some arbitrary directory (as returned by os.listdir()). Also, never name a variable "file"; it shadows the name of the built-in t

Re: easy question on parsing python: "is not None"

2010-08-09 Thread Dave Angel
saeed.gnu wrote: On Aug 9, 3:41 pm, "saeed.gnu" wrote: "x is y" means "id(y) =id(y)" "x is not y" means "id(x) !=d(x)" "x is not None" means "id(x) !=d(None)" "x is not None" is a really silly statement!! because id(None) and id of any constant object is not predictab

Re: simple renaming files program

2010-08-09 Thread Dave Angel
MRAB wrote: from os.path import isdir, join Have a look at the imports, Dave. :-) Oops. I should have noticed that it was a function call, not a method. And there's no built-in called join(). I just usually avoid using this kind of alias, unless performance requires. thanks for ke

Re: Newbie question - calculating prime numbers

2010-08-10 Thread Dave Angel
Matty Sarro wrote: Hey Everyone, I'm currently trying to work through MIT's opencourseware and am using python. The second assignment they offer is to determine the 1000th prime number. Below is the code I am using: #Assignment 1a #Determine the 1000th prime number candidate=3 #Already know that

Re: Newbie question - calculating prime numbers

2010-08-10 Thread Dave Angel
Matty Sarro wrote: Hey Dave, Thank you for the heads up. I actually bashed my head against the desk a few times and eventually I realized what I was doing wrong. Here's my final code (slightly optimized) that's verified and working. Out of curiousity, what other optimizations could I throw at it

Re: Confused: Newbie Function Calls

2010-08-11 Thread Dave Angel
fuglyducky wrote: I am a complete newbie to Python (and programming in general) and I have no idea what I'm missing. Below is a script that I am trying to work with and I cannot get it to work. When I call the final print function, nothing prints. However, if I print within the individual functio

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-12 Thread Dave Angel
Roald de Vries wrote: On Aug 12, 2010, at 11:33 AM, Paul Rubin wrote: Baba writes: exercise: given that packs of McNuggets can only be bought in 6, 9 or 20 packs, write an exhaustive search to find the largest number of McNuggets that cannot be bought in exact quantity. Is that a homework

Re: Programming Puzzles? What's your favorite puzzle?

2010-08-12 Thread Dave Angel
Matty Sarro wrote: Hey All! Hope your thursday is treating you well. I'm looking for suggestions on books of programming/engineering puzzles that range from beginners to advanced and even expert level problems. I know they exist; we had them back in college for practicing before the ACM programmi

Re: Importing libs on Windows?

2010-08-13 Thread Dave Angel
Brian Salter wrote: It appears that every example is calling a dll, and I'm looking to bring in a lib. Does ctypes work with libs too? "Gary Herron" wrote in message news:mailman.2044.1281656800.1673.python-l...@python.org... On 08/12/2010 04:09 PM, Brian Salter wrote: I've seen a number of

Re: How do I get number of files in a particular directory.

2010-08-13 Thread Dave Angel
blur959 wrote: On Aug 13, 6:09 pm, Peter Otten <__pete...@web.de> wrote: blur959 wrote: Hi, I tried that, but it doesn't seem to work. My file directory has many different files extensions, and I want it to return me a number based on the number of files with similar files extensions. B

Re: Pop return from stack?

2010-08-15 Thread Dave Angel
Steven D'Aprano wrote: On Sat, 14 Aug 2010 16:05:05 -0700, bvdp wrote: def error(s): print "Error", s sys.exit(1) This general technique is called "monkey patching". You can either manually exit from your own error handler: def myerror(s): print "new error message

Re: shelf-like list?

2010-08-15 Thread Dave Angel
kj wrote: self.save() Even though it is saved periodically to disk, it looks like the whole list remains in memory all the time? (If so, it's not what I'm looking for; the whole point of saving stuff to disk is to keep the list's memory footprint low.) ~K It sounds like

Re: Python "why" questions

2010-08-15 Thread Dave Angel
Roald de Vries wrote: On Aug 15, 2010, at 2:16 PM, geremy condra wrote: On Sun, Aug 15, 2010 at 4:55 AM, Roald de Vries wrote: On Aug 15, 2010, at 1:00 PM, Lawrence D'Oliveiro wrote: It would be if pointers and arrays were the same thing in C. Only they’re not, quite. Which somewhat defeats

Re: Iterative vs. Recursive coding

2010-08-19 Thread Dave Angel
Baba wrote: Level: Beginner exercise source: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset3.pdf I am looking at the first problem in the above assignment. The assignemnt deals, amongst oth

<    19   20   21   22   23   24   25   26   27   >