Re: strptime not strict enough

2009-12-16 Thread Lie Ryan
On 12/15/2009 10:30 AM, Tobias Weber wrote: Hi, despite the directives for leading zero stime.strptime('09121', '%y%m%d') returns the first of December. Shouldn't it raise ValueError? Where do I get strict date parsing? A bit hackish perhaps, but maybe you can check for the date's length: dat

Re: (OT) Where Are Cookies Stored?

2009-12-17 Thread Lie Ryan
On 12/17/2009 2:33 AM, Dave Angel wrote: Victor Subervi wrote: On Tue, Dec 15, 2009 at 6:57 PM, r0g wrote: Cookies in FF for Windows are stored in an sqlite database in here... ~\Application Data\Mozilla\Firefox\Profiles\%XYZ%\firefox_profile\ Man, I searched C drive (the only drive) o

ANN: withrestart 0.2.1

2009-12-17 Thread Ryan Kelly
demo of the module in action, keep reading... Cheers, Ryan About withrestart: -- Version: 0.2.1 Licence: MIT Source: http://github.com/rfk/withrestart withrestart is a Pythonisation (Lispers might rightly say "bastardisation") of the restart-based condition

Re: Line indexing in Python

2009-12-18 Thread Lie Ryan
On 12/19/2009 3:27 AM, seafoid wrote: Thanks for that Richard and Steve. I have another question. What's the question? fname = raw_input('Please enter the name of the file: ') # create file objects blah = open(fname, 'r') a = open('rubbish', 'w') for line in blah: if line.startswith

Re: Line indexing in Python

2009-12-18 Thread Lie Ryan
On 12/19/2009 4:33 AM, seafoid wrote: Thanks for that Lie. I had to have a think about what you meant when you referred to control going to a.write(line). and if-elif-elif-... chain is executed sequentially and when a match is found, the rest of the chain is skipped. Your code: if line.sta

Re: Raw string substitution problem

2009-12-18 Thread Lie Ryan
On 12/19/2009 4:59 AM, Alan G Isaac wrote: On 12/18/2009 12:17 PM, MRAB wrote: In simple cases you might be replacing with the same string every time, but other cases you might want the replacement to contain substrings captured by the regex. Of course that "conversion" is needed in the repla

Re: subprocess.Popen and ordering writes to stdout and stderr

2009-12-18 Thread Lie Ryan
On 12/18/2009 8:15 AM, Chris Withers wrote: the order of the writes isn't preserved. How can I get this to be the case? You'll need to flush the std{out|err} or set them unbuffered; or you can just forget about relying on std{out|err} being ordered per write-order. -- http://mail.python

Re: iterators and views of lists

2009-12-18 Thread Lie Ryan
On 12/18/2009 7:07 AM, Brendan Miller wrote: As for copying pointers not taking much time... that depends on how long the list is. if you are working with small sets of data, you can do almost anything and it will be efficient. However, if you have megabytes or gigabytes of data (say you are work

Re: ANN: withrestart 0.2.1

2009-12-18 Thread Ryan Kelly
test_restarts2: 90.20 usec Not having to pass status flags or callback functions through every layer of your API to properly recover from errors: tryexcept:impossible :-( withrestart: priceless :-) Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is d

Re: shouldn't list comprehension be faster than for loops?

2009-12-18 Thread Ryan Kelly
return map(lambda i: i*2,xrange(10)) ... >>> dis.dis(maper) 2 0 LOAD_GLOBAL 0 (map) 3 LOAD_CONST 1 (>> Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk

Re: Sort the values of a dict

2009-12-18 Thread Lie Ryan
On 12/19/2009 9:34 AM, mattia wrote: Can you provide me a much pythonic solution (with comments if possible, so I can actually learn something)? If you only need to get i'th element sometimes, sorting the dict is fine. Otherwise, you might want to use collections.OrderedDict. -- http://mail.p

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - RequestFor Comments

2009-12-18 Thread Lie Ryan
On 12/19/2009 12:56 PM, Steven D'Aprano wrote: As far as I know, no programming language provides a standard facility for renaming entities, be they data or routines: The C-preprocessor does to C/C++, in a limited fashion. -- http://mail.python.org/mailman/listinfo/python-list

Re: Object Relational Mappers are evil (a meditation)

2009-12-18 Thread Lie Ryan
On 12/17/2009 3:17 PM, J Kenneth King wrote: A language is a thing. It may have syntax and semantics that bias it towards the conventions and philosophies of its designers. But in the end, a language by itself would have a hard time convincing a human being to adopt bad practises. Perhaps som

Re: iterators and views of lists

2009-12-18 Thread Lie Ryan
On 12/17/2009 4:44 AM, Francesco Bochicchio wrote: On Dec 16, 1:58 pm, Anh Hai Trinh wrote: You might be interested in this library. You can easily create arbitrary "slice", for example i = mylist>> takei(primes()) will return an iterator over the i

Re: py itertools?

2009-12-19 Thread Lie Ryan
On 12/19/2009 11:48 PM, Chris Rebert wrote: Surprised you didn't think of the seemingly obvious approach: def permute_chars(one, two): for left in set(one): for right in set(two): yield (left, right) list(permute_chars('abc', 'wt')) [('a', 'w'), ('a', 't'), ('b', '

Re: numpy performance and random numbers

2009-12-19 Thread Lie Ryan
On 12/20/2009 4:02 AM, Carl Johan Rehn wrote: How did you time it? Well, in Matlab I used "tic; for i = 1:1000, randn(100, 1), end; toc" and in IPython i used a similar construct but with "time" instead of tic/(toc. Code? Parallel PRNGs are an unsolved problem in computer science. Tha

Re: Class variables static by default?

2009-12-19 Thread Lie Ryan
On 12/20/2009 11:10 AM, KarlRixon wrote: Given the following script, I'd expect p1.items to just contain ["foo"] and p2.items to contain ["bar"] but they both contain ["foo", "bar"]. Why is this? Are object variables not specific to their instance? First of all, dump all the preconception of w

Re: numpy performance and random numbers

2009-12-19 Thread Lie Ryan
On 12/20/2009 8:58 AM, sturlamolden wrote: On 19 Des, 21:26, Lie Ryan wrote: you can just start two PRNG at two distinct states No. You have to know for certain that the outputs don't overlap. Not necessarily, you only need to be certain that the two streams don't over

Re: numpy performance and random numbers

2009-12-20 Thread Lie Ryan
On 12/20/2009 2:53 PM, sturlamolden wrote: On 20 Des, 01:46, Lie Ryan wrote: Not necessarily, you only need to be certain that the two streams don't overlap in any reasonable amount of time. For that purpose, you can use a PRNG that have extremely high period like Mersenne Twister and

Re: numpy performance and random numbers

2009-12-20 Thread Lie Ryan
On 12/21/2009 1:13 AM, David Cournapeau wrote: But the OP case mostly like falls in your estimated 0.01% case. PRNG quality is essential for reliable Monte Carlo procedures. I don't think long period is enough to guarantee those good properties for // random generators - at least it is not obviou

Re: Windows, IDLE, __doc_, other

2009-12-20 Thread Lie Ryan
On 12/21/2009 1:19 PM, W. eWatson wrote: When I use numpy.__doc__ in IDLE under Win XP, I get a heap of words without reasonable line breaks. "\nNumPy\n=\n\nProvides\n 1. An array object of arbitrary homogeneous items\n 2. Fast mathematical operations over arrays\n 3. Linear Algebra, F

Re: Windows, IDLE, __doc_, other

2009-12-21 Thread Lie Ryan
On 12/22/2009 6:39 AM, W. eWatson wrote: Wow, did I get a bad result. I hit Ctrl-P, I think instead of Alt-P, and a little window came up showing it was about to print hundreds of pages. I can canceled it, but too late. I turned off my printer quickly and eventually stopped the onslaught. I coul

Re: How to validate the __init__ parameters

2009-12-21 Thread Lie Ryan
On 12/22/2009 4:41 AM, Denis Doria wrote: Hi; I'm checking the best way to validate attributes inside a class. Of course I can use property to check it, but I really want to do it inside the __init__: class A: def __init__(self, foo, bar): self.foo = foo #check if foo is correct

Re: more efficient?

2009-12-22 Thread Lie Ryan
On 12/22/2009 5:13 PM, Zubin Mithra wrote: I have the following two implementation techniques in mind. def myfunc(mystring): check = "hello, there " + mystring + "!!!" print check OR structure = ["hello, there",,"!!!"] def myfunc(mystring): structure[2] = mystring output =

Re: How to validate the __init__ parameters

2009-12-22 Thread Lie Ryan
On 12/22/2009 8:52 PM, Bruno Desthuilliers wrote: Steve Holden a écrit : (snip) What's the exact reason for requiring that a creator argument be of a specific type? So operations on the instances don't go wrong? Well, why not just admit that we don't have control over everything, and just *let t

Re: Line indexing in Python

2009-12-22 Thread Lie Ryan
On 12/22/2009 11:25 PM, Steve Holden wrote: > > If you want to extract an index number from the first part of of a given > line use split( split_character, maximum_splits_to_do ) and then angle > brackets to reference the first part (index 0)... > > a = "20 GOTO 10" int( a.split('

Re: Windows, IDLE, __doc_, other

2009-12-22 Thread Lie Ryan
On 12/22/2009 12:06 PM, W. eWatson wrote: Stephen Hansen wrote: On Mon, Dec 21, 2009 at 2:57 PM, W. eWatson wrote: [snip Now, I go to the script and enter from math import * dir is now bulked up with the math functions. I change back math.cos to cos and the program runs well. This sort of fig

Re: Threading with queues

2009-12-22 Thread Lie Ryan
On 12/22/2009 10:47 AM, Gib Bogle wrote: This is indented over one indentation level too much. You want it to be at the same level as the for above. Here, its at the same level with "t" -- meaning this entire loop gets repeated five times. I sorta really recommend a tab width of 4 spaces, not 2

Re: Python (and me) getting confused finding keys

2009-12-22 Thread Lie Ryan
On 12/23/2009 3:33 AM, John wrote: Hi there, I have a rather lengthy program that troubles me for quite some time. After some debugging, I arrived at the following assertion error: for e in edges.keys(): assert edges.has_key(e) Oops!? Is there ANY way that something like this can possi

Re: Problem with Dynamically unloading a module

2009-12-23 Thread Lie Ryan
On 12/23/2009 8:41 PM, lordofcode wrote: Hi All Not an expert in Python, so sorry if this sounds like a silly question. I went through other few threads in the mailing list but they are not helping me much. I have run into a problem related to dynamically loading and unloading a module. I need t

Re: code review

2009-12-23 Thread Lie Ryan
On 12/23/2009 11:02 PM, Zubin Mithra wrote: Hello, I`m pretty new to developing applications using python and i would like advance on this script i recently created which helps linux programmers on the linux terminal. The code is very simple to understand(i hope) and serves a simple purpose; how

Re: More On the Strange Problem

2009-12-23 Thread Lie Ryan
On 12/24/2009 8:00 AM, MRAB wrote: >>> print first_twin == second_twin True err... I don't think there is any situation where first_twin == second_twin wouldn't be considered a bug. They look similar, they act similar, and they quack the same; though you can almost always treat them the sa

Re: creating ZIP files on the cheap

2009-12-23 Thread Lie Ryan
On 12/24/2009 7:34 AM, samwyse wrote: I've got an app that's creating Open Office docs; if you don't know, these are actually ZIP files with a different extension. In my case, like many other people, I generating from boilerplate, so only one component (content.xml) of my ZIP file will ever chan

Re: Object Relational Mappers are evil (a meditation)

2009-12-24 Thread Lie Ryan
On 12/24/2009 12:11 PM, Terry Reedy wrote: This buggy idiom survived many years of Python development, missed by virtually everyone. The last statement is false. The hazard of using and/or was well-known back in '97 or so when I discovered or learned it and I believe it was mentioned in the FAQ

Re: Join a thread and get the return value of a function

2009-12-24 Thread Lie Ryan
On 12/25/2009 12:23 AM, mattia wrote: Hi all, is there a way in python to get back the value of the function passed to a thread once the thread is finished? Something like pthread_join() in C? Thanks, Mattia use a Queue to pass the value out? -- http://mail.python.org/mailman/listinfo/python-l

Re: Problem with Dynamically unloading a module

2009-12-24 Thread Lie Ryan
On 12/24/2009 11:51 PM, Jean-Michel Pichavant wrote: But what he *can* do is to learn how importing works. I'm not sure it's terribly helpful to tell somebody all the things they can't do instead of what they can. Hacking python imports would not be in the top of the list of things I would tea

Re: Join a thread and get the return value of a function

2009-12-24 Thread Lie Ryan
On 12/25/2009 2:02 AM, mattia wrote: Il Fri, 25 Dec 2009 00:35:55 +1100, Lie Ryan ha scritto: On 12/25/2009 12:23 AM, mattia wrote: Hi all, is there a way in python to get back the value of the function passed to a thread once the thread is finished? Something like pthread_join() in C

Re: Threading with queues

2009-12-24 Thread Lie Ryan
On 12/24/2009 2:11 PM, Gib Bogle wrote: Lie Ryan wrote: On 12/22/2009 10:47 AM, Gib Bogle wrote: It turns out that this code isn't a great demo of the advantages of threading, on my system anyway. The time taken to execute doesn't vary much when the number of threads is set anywhere

Re: Missing collections

2009-12-27 Thread Lie Ryan
On 12/27/2009 4:53 PM, Bearophile wrote: - frozenDict perhaps we could extend namedtuple to become the "frozenDict" - persistentList, persistentDict aren't they database? Am I missing something here? Regarding the standard library of Python 3, it's easy enough to create for mistake a modu

Re: Difference Between Two datetimes

2009-12-27 Thread Lie Ryan
On 12/28/2009 5:42 PM, W. eWatson wrote: You're right. Y. Works fine. The produces datetime.datetime(2009, 1, 2, 13, 1, 15). If I now use t2=datetime.datetime.strptime("2009/01/04 13:01:15","%Y/%m/%d %H:%M:%S") I get tw as datetime.datetime(2009, 1, 4, 13, 1, 15) Then t2-t1 gives, datetime.timede

Re: Simple distributed example for learning purposes?

2009-12-28 Thread Lie Ryan
On 12/27/2009 7:46 AM, Shawn Milochik wrote: The special features of the Shrek DVD showed how the rendering took so much processing power that everyone's workstation was used overnight as a rendering farm. Some kind of video rendering would make a great example. However, it might be a lot of ov

Re: Difference Between Two datetimes

2009-12-28 Thread Lie Ryan
On 12/29/2009 1:12 AM, Roy Smith wrote: Hint #3: If you don't pay attention to this, you will be bitten twice a year. Not really. Some areas don't have DST and the answer to that is always exactly 5 months. -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple distributed example for learning purposes?

2009-12-28 Thread Lie Ryan
On 12/28/2009 11:59 PM, Shawn Milochik wrote: With address data: one address may have suite data and the other might not the same city may have multiple zip codes why is that even a problem? You do put suite data and zipcode into different database fields right? inc

Re: How to iterate the input over a particular size?

2009-12-28 Thread Lie Ryan
On 12/28/2009 8:54 PM, Peter Otten wrote: Francesco Bochicchio wrote: One with lazy chunks: from itertools import chain, islice def chunks(items, n): items = iter(items) for first in items: yield chain((first,), islice(items, n-1)) [list(chunk) for chun

Re: Windows, IDLE, __doc_, other

2009-12-28 Thread Lie Ryan
On 12/29/2009 5:10 AM, W. eWatson wrote: Lie Ryan wrote: If you're on Windows, don't use the "Edit with IDLE" right-click hotkey since that starts IDLE without subprocess. Use the shortcut installed in your Start menu. When I go to Start and select IDLE, Saves or Ope

Re: clean data [was: Simple distributed example for learning purposes?]

2009-12-29 Thread Lie Ryan
On 12/29/2009 9:14 AM, Ethan Furman wrote: Lie Ryan wrote: On 12/28/2009 11:59 PM, Shawn Milochik wrote: With address data: one address may have suite data and the other might not the same city may have multiple zip codes why is that even a problem? You do put suite data and zipcode into

Re: Python OOP Problem

2009-12-29 Thread Lie Ryan
On 12/29/2009 3:01 PM, Миклухо wrote: On 28 дек, 18:29, "Martin v. Loewis" wrote: In this case (you just started to learn Python), I recommend to take an explicit approach. Create a dictionary that maps class names to classes: name2class = { "MyObject" : MyObject, "MyOtherObjec

Re: I think I found a bug in Python 2.6.4 (in the inspect module)

2009-12-30 Thread Lie Ryan
On 12/30/2009 9:10 AM, inhahe wrote: Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. import inspect def a(b=1): pass inspect.getargvalues(a) Traceback (most recent call last):

Re: Windows, IDLE, __doc_, other

2009-12-30 Thread Lie Ryan
On 12/30/2009 6:21 AM, W. eWatson wrote: Lie Ryan wrote: On 12/29/2009 5:10 AM, W. eWatson wrote: Lie Ryan wrote: If you're on Windows, don't use the "Edit with IDLE" right-click hotkey since that starts IDLE without subprocess. Use the shortcut installed in your Start

Re: Dynamic text color

2009-12-31 Thread Lie Ryan
On 1/1/2010 2:24 AM, Dave McCormick wrote: If I count characters from the beginning how do I know what line the text is on? Would you mind making your last hint a bit stronger... From http://infohost.nmt.edu/tcc/help/pubs/tkinter/text-index.html: """ + n chars From the given index, move f

Re: multivariable assignment

2010-01-01 Thread Lie Ryan
On 1/1/2010 3:13 AM, davidj411 wrote: I am not sure why this behavior is this way. at beginning of script, i want to create a bunch of empty lists and use each one for its own purpose. however, updating one list seems to update the others. a = b = c = [] a.append('1') a.append('1') a.append('1'

Re: Where is "urllib2" module in windows python3.1.1?

2010-01-01 Thread Lie Ryan
On 1/2/2010 12:46 AM, Hidekazu IWAKI wrote: Hi; I'd like to import "urllib2" in windows python 3.1.1, but I'm not able to do it. So, I researched the library directory; the result is following: . . 2009/06/07 19:1161,749 unittest.py 2010/01/01 22:18 urllib 2007/12

Re: Exception as the primary error handling mechanism?

2010-01-01 Thread Lie Ryan
On 1/1/2010 3:47 PM, Peng Yu wrote: I observe that python library primarily use exception for error handling rather than use error code. In the article API Design Matters by Michi Henning Communications of the ACM Vol. 52 No. 5, Pages 46-56 10.1145/1506409.1506424 http://cacm.acm.org/magazines/

Re: Bare Excepts

2010-01-02 Thread Lie Ryan
On 1/2/2010 9:42 PM, Steven D'Aprano wrote: On Fri, 01 Jan 2010 15:27:57 -0800, myle wrote: Why we should prefer ``if: ...'' over a ``try: ... except something: pass'' block? We shouldn't, not in general. One exception (pun intended) is if the try-block have a side effect that is difficul

Re: detect interactivity

2010-01-03 Thread Lie Ryan
On 12/30/2009 11:25 PM, Roald de Vries wrote: Actually, performance is not much if an issue for what I want to do; it's mainly interest in 'how should I do this in general'. I'll just leave in all the code, and if it becomes a real issue, I'll separate the code over an interactive and a non-inter

Re: What is the best data structure for a very simple spreadsheet?

2010-01-03 Thread Lie Ryan
On 1/3/2010 10:27 PM, vsoler wrote: 1) what are, in your opinion, the basic elements of the Cell class? The "user-entered formula" and "effective value". A Cell containing a formula "abc" has a value of "abc"; a cell containing the formula "=1+5" has a value of "6". You could use the 'proper

Re: Exception as the primary error handling mechanism?

2010-01-04 Thread Lie Ryan
On 1/5/2010 1:31 PM, r0g wrote: Michi wrote: On Jan 4, 1:30 pm, Steven D'Aprano wrote: In some, limited, cases you might be able to use the magic return value strategy, but this invariably leads to lost programmer productivity, more complex code, lowered readability and usability, and more

Re: Exception as the primary error handling mechanism?

2010-01-05 Thread Lie Ryan
On 1/6/2010 1:48 AM, r0g wrote: Steven D'Aprano wrote: On Tue, 05 Jan 2010 13:06:20 +, r0g wrote: If that's the case how can you expect it to validate anything at all in production? The asserts still operate so long as you don't use the -O switch. Do you mean for debugging in situ or so

Re: Exception as the primary error handling mechanism?

2010-01-06 Thread Lie Ryan
On 1/7/2010 2:12 AM, Phlip wrote: On Jan 5, 10:54 pm, Benjamin Kaplan wrote: {41: None}[41] ? In cases where None is a valid result, you can't use it to signal failure.. Asked and answered. You change the "sentinel" in .fetch to something else. I believe Ben Kaplan's point is that if dict

Re: Exception as the primary error handling mechanism?

2010-01-06 Thread Lie Ryan
On 1/7/2010 3:41 AM, Phlip wrote: Steve Holden wrote: y'all just keep defending the approach to programming that *you* think is best. Speak for yourself... Everyone speaks for themselves, is that a problem? -- http://mail.python.org/mailman/listinfo/python-list

Re: File transfer with python

2010-01-06 Thread Lie Ryan
On 1/7/2010 5:00 AM, Valentin de Pablo Fouce wrote: My intention is to be able to transfer files from one computer to another in this environment. Do you have a USB flashdrive? Looking (and surfing) at internet the only suggestion given is to use low level sockets for this file transfer. Is t

Re: Exception as the primary error handling mechanism?

2010-01-07 Thread Lie Ryan
On 1/7/2010 10:43 PM, Roel Schroeven wrote: - I tend to think that not following that practice trains me to be careful in all cases, whereas I'm afraid that following the practice will make me careless, which is dangerous in all the cases where the practice won't protect me. That's a sign of a

Re: Recommended "new" way for config files

2010-01-07 Thread Lie Ryan
On 1/8/2010 3:10 AM, Peter wrote: Is there a strategy that should be prefered for new projects ? The answer is, it depends. -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help to pass self.count to other classes.

2010-01-08 Thread Lie Ryan
On 1/8/2010 3:56 PM, Steven D'Aprano wrote: Unfortunately this won't do what you expect, because sys.ps1 and ps2 should be either strings, or objects with a __str__ method. They aren't called to generate the prompt. but their __str__ does get called to generate the prompt. import sys class kb

Re: PIL how to display multiple images side by side

2010-01-09 Thread Lie Ryan
On 1/9/2010 8:43 AM, suresh.amritapuri wrote: Hi, In PIL, how to display multiple images in say m rows and n colums when I have m*n images. suresh Tkinter has PhotoImage widget and PIL has support for this widget: http://www.pythonware.com/library/pil/handbook/imagetk.htm -- http://mail.pyt

Re: decode(..., errors='ignore') has no effect

2010-01-12 Thread Lie Ryan
On 01/12/10 23:50, Jens Müller wrote: >> To convert unicode into str you have to *encode()* it. >> >> u"...".decode(...) will implicitly convert to ASCII first, i. e. is >> equivalent to >> >> u"...".encode("ascii").decode(...) >> >> Hence the error message > > Ah - yes of course. > > And how can

Re: Bugs in CPython 3.1.1 [wave.py]

2010-01-13 Thread Lie Ryan
Alf P. Steinbach wrote: > * Stefan Behnel: >> Alf P. Steinbach, 13.01.2010 06:39: >>> * Steven D'Aprano: On Tue, 12 Jan 2010 23:42:28 +0100, Alf P. Steinbach wrote: > It is hopeless, especially for a newbie, to create correct Python > 2.x+3.x compatible code, except totally trivial stu

Re: os.system function

2010-01-13 Thread Lie Ryan
On 01/13/10 04:59, r0g wrote: > so you may want to look into pythons core GUI library, TKL. I know Tk and Tcl has been close since their childhood; did they get married too? -- http://mail.python.org/mailman/listinfo/python-list

Re: Those two controversial 2nd & 3rd paragraphs of my ch 1

2010-01-14 Thread Lie Ryan
On 01/14/10 11:08, Alf P. Steinbach wrote: > * Daniel Fetchinson: >> >> Nobody is deliberately trying to keep people from porting! I think you >> misunderstand what is being said, these two statements are very >> different: (1) single code base working on both python versions (2) >> creating a seco

Re: a problem with writing a generator

2010-01-14 Thread Lie Ryan
On 01/15/10 01:49, Steven D'Aprano wrote: > On Thu, 14 Jan 2010 15:11:29 +0100, Paweł Banyś wrote: > >> Hello, >> >> Please forgive me if I repeat the subject anyhow. I am trying to write a >> simple program in Python which scans a config file in search for >> "include" lines. If those lines are f

Re: A simple-to-use sound file writer

2010-01-14 Thread Lie Ryan
On 01/15/10 05:42, Alf P. Steinbach wrote: > I'm beginning to believe that you maybe didn't grok that simple procedure. > > It's very very very trivial, so maybe you were looking for something > more intricate -- they used to say, in the old days, "hold on, this > proof goes by so fast you may n

Re: maintain 2 versions of python on my computer

2010-01-14 Thread Lie Ryan
On 01/14/10 22:21, luis wrote: > > Hi > > I am not an expert in programming and using Python for its simplicity > > I have 2 versions of python installed on my computer (windos xp) to > begin the transition from version 2.4 to 2.6 or 3. maintaining the > operability of my old scripts > > Is the

Re: Executable standalone *.pyc after inserting "#!/usr/bin/python"or other options

2010-01-14 Thread Lie Ryan
On 01/15/10 09:33, Martin v. Loewis wrote: > > P.S. The approach you present for Lua indeed does not work for > Python. Actually the approach should work, though with a little workaround; you can write your wrapper (e.g. #!/usr/bin/mypython) that simply strips the first line and pass the file to

Re: dict's as dict's key.

2010-01-15 Thread Lie Ryan
On 01/14/10 05:33, Albert van der Horst wrote: > (I encountered this before. A dictionary is a natural for a > boardgame position, i.e. chess. Now we want to look up chess > positions.) or use collections.namedtuple -- http://mail.python.org/mailman/listinfo/python-list

Re: setattr() oddness

2010-01-16 Thread Lie Ryan
On 01/16/10 10:10, Sean DiZazzo wrote: > Interesting. I can understand the "would take time" argument, but I > don't see any legitimate use case for an attribute only accessible via > getattr(). Well, at least not a pythonic use case. mostly for people (ab)using attributes instead of dictionary.

Re: Using invalid.com email addresses

2010-01-16 Thread Lie Ryan
On 01/16/10 19:56, Ben Finney wrote: > Paul Rubin writes: > >> I'd think whoever registered that domain would have known what they >> were getting into when they registered it. Same with "example.com" and >> so forth. > > Which doesn't make it any more appropriate to act as though you have > fre

Re: chr(12) Form Feed in Notepad (Windows)

2010-01-16 Thread Lie Ryan
On 01/17/10 02:37, W. eWatson wrote: > D'Arcy J.M. Cain wrote: >> On Fri, 15 Jan 2010 20:17:35 -0800 >> "W. eWatson" wrote: >>> Could be, but I have no way of easily knowing. In any case, I was >>> trying to write a simple report that could be printed with titles at >>> the top of each page. If th

Re: dict's as dict's key.

2010-01-17 Thread Lie Ryan
On 01/17/10 12:29, Ethan Furman wrote: > Lie Ryan wrote: >> On 01/14/10 05:33, Albert van der Horst wrote: >> >>> (I encountered this before. A dictionary is a natural for a >>> boardgame position, i.e. chess. Now we want to look up chess >>> position

Re: The answer

2010-01-17 Thread Lie Ryan
On 01/18/10 13:30, Jive Dadson wrote: > Okay, with your help I've figured it out. Instructions are below, but > read the caveat by Ben Fenny in this thread. All this stuff is good for > one default version of Python only. The PYTHONPATH described below, for > example, cannot specify a version nu

Re: Python decorator syntax limitations

2010-01-18 Thread Lie Ryan
On 01/19/10 03:44, Jonathan S wrote: > Any suggestions? I have my reasons for doing this, (news_page is a > class, and __call__ is used to wrap the template.) > I'm sure this is a limitation in the syntax, but would parenthesis > somewhere help? The restriction[1] is put in there since Guido has a

Re: how to check if a module is importable?

2010-01-20 Thread Lie Ryan
On 01/20/10 19:58, Robert P. J. Day wrote: > > finally getting back to clawing my way thru the python 3 book so > probably a number of newbie questions coming up. first one -- can i > check if a module is importable (equivalently, exists on sys.path, i > assume) without trying to import it firs

Re: examining an initial, pristine python3 shell session

2010-01-20 Thread Lie Ryan
On 01/20/10 22:59, Robert P. J. Day wrote: > then i might go a bit further to examine some of *those* objects. i > admit it might seem a bit dry, but i think it would be handy to have a > handle on what a clean shell session looks like before starting to > import things, then seeing how that impor

Re: myths about python 3

2010-01-27 Thread Lie Ryan
On 01/28/10 01:32, Jean-Michel Pichavant wrote: > Daniel Fetchinson wrote: Hi folks, I was going to write this post for a while because all sorts of myths periodically come up on this list about python 3. I don't think the posters mean to spread false information on purpose

interaction of mode 'r+', file.write(), and file.tell(): a bug or undefined behavior?

2010-01-28 Thread Lie Ryan
In the code: """ f = open('input.txt', 'r+') for line in f: s = line.replace('python', 'PYTHON') # f.tell() f.write(s) """ When f.tell() is commented, 'input.txt' does not change; but when uncommented, the f.write() succeeded writing into the 'input.txt' (surprisingly, but not entirel

Re: Stuck on a three word street name regex

2010-01-28 Thread Lie Ryan
On 01/28/10 11:28, Brian D wrote: > I've tackled this kind of problem before by looping through a patterns > dictionary, but there must be a smarter approach. > > Two addresses. Note that the first has incorrectly transposed the > direction and street name. The second has an extra space in it befo

Re: python 3's adoption

2010-01-28 Thread Lie Ryan
On 01/28/10 19:37, Paul Rubin wrote: > Jonathan Gardner writes: >> If you're going to have statements, you're going to need the null >> statement. That's "pass". > > Why? Expressions are statements, so you could just say "pass" (in > quotes, denoting a string literal), or 0, or None, os anything

Re: python 3's adoption

2010-01-28 Thread Lie Ryan
On 01/28/10 20:12, Alf P. Steinbach wrote: > * Steven D'Aprano: >> On Wed, 27 Jan 2010 18:29:25 +0100, Alf P. Steinbach wrote:> >> Instead of: >> >> print >>fileObj, x, y, z >> >> you use regular function syntax with a meaningful keyword: >> >> print(x, y, z, file=fileObj) >> >> If you want suppres

Re: [Tutor] Help required

2009-09-26 Thread Lie Ryan
waqas ahmad wrote: Now i want to search all those pages, where i have *NOT* written "#acl InternationalGroup:read" *But* i have written only "CatInternational" in the page text. You can split the two queries into two regexes: import re acl = re.compile(r'#acl InternationalGroup:read') cat =

Re: print()

2009-10-17 Thread Lie Ryan
mattia wrote: Another question (always py3). How can I print only the first number after the comma of a division? e.g. print(8/3) --> 2.667 I just want 2.6 (or 2.66) Are you sure you don't want that to be 2.7 or 2.67? Then you can use: n = int(n * 10**2) / 10**2 else if 2.7 pr 2.67 is

Re: More & More Fun w/ Pics & MySQL

2009-10-17 Thread Lie Ryan
Carsten Haese wrote: Victor Subervi wrote: [snip...] print 'Content-type: image/jpeg' print 'Content-Encoding: base64' print print pic().encode('base64') print '' [snip...] Why are you printing "" at the end of a page that is supposed to be a base64-encoded JPEG file? I'm testing my "psych

Re: a gap of do....while?

2009-10-18 Thread Lie Ryan
Chris Rebert wrote: On Sat, Oct 17, 2009 at 10:22 PM, StarWing wrote: okay, I think somethings dowhile is useful, but why python didn't have it? For simplicity of syntax and less duplication among the basic syntactic constructs. Less language features means less decisions to make. -- ht

Re: The rap against "while True:" loops

2009-10-18 Thread Lie Ryan
Paul Rubin wrote: Steven D'Aprano writes: For the record, the four lines Paul implies are "confusing" are: try: d[key] += value except KeyError: d[key] = value Consider what happens if the computation of "key" or "value" itself raises KeyError. Isn't key and value just a simple var

Re: The rap against "while True:" loops

2009-10-18 Thread Lie Ryan
Ben Finney wrote: Lie Ryan writes: Paul Rubin wrote: Steven D'Aprano writes: For the record, the four lines Paul implies are "confusing" are: try: d[key] += value except KeyError: d[key] = value Consider what happens if the computation of "key" or "

Re: help to convert c++ fonction in python

2009-10-18 Thread Lie Ryan
Thomas wrote: If you change your last line from: print s to: print u you'll get different results :) if you change: s1 = base64.b64decode( s ) into s = base64.b64decode( s ) you'll get the same result again. -- http://mail.python.org/mailman/listinfo/python-list

Re: More & More Fun w/ Pics & MySQL

2009-10-18 Thread Lie Ryan
Carsten Haese wrote: Victor Subervi wrote: Thank you all. I have __no__idea__ why the link I sent you, that you tested, __didn't__ work for me. Was it a problem with the browser? My Magic 8-Ball says "Unclear. Ask again later." Regarding Carsten's misunderstanding of my mentioning of comment

Re: Reverse Iteration Through Integers

2009-10-18 Thread Lie Ryan
Benjamin Middaugh wrote: I'm trying to make an integer that is the reverse of an existing integer such that 169 becomes 961. I guess I don't know enough yet to figure out how to do this without a ton of awkward-looking code. I've tried for loops without much success. I guess I need a good way o

Re: Checking a Number for Palindromic Behavior

2009-10-21 Thread Lie Ryan
ru...@yahoo.com wrote: 1) It may look like a homework problem to you but it probably isn't. Seehttp://groups.google.com/group/comp.lang.python/msg/8ac6db43b09fdc92 Homework comes in many forms - school driven homework should be treated the same as self driven research, IMO. You're not doing it

Re: Windows file paths, again

2009-10-21 Thread Lie Ryan
Dan Guido wrote: Hi Anthony, Thanks for your reply, but I don't think your tests have any control characters in them. Try again with a \v, a \n, or a \x in your input and I think you'll find it doesn't work as expected. A path read from a file, config file, or winreg would never contain contr

Re: Checking a Number for Palindromic Behavior

2009-10-21 Thread Lie Ryan
ru...@yahoo.com wrote: On 10/21/2009 01:40 AM, Lie Ryan wrote: ru...@yahoo.com wrote: 1) It may look like a homework problem to you but it probably isn't. Seehttp://groups.google.com/group/comp.lang.python/msg/8ac6db43b09fdc92 Homework comes in many forms - school driven homework shou

Re: equivalent to globals(), locals() for nonlocal variables?

2009-10-22 Thread Lie Ryan
geremy condra wrote: I decided to play around with nonlocal declarations today, and was somewhat surprised when a call to nonlocals() resulted in 'nonlocals is not defined'. Is there an a standard equivalent to globals() or locals() for variables in outer nested scopes? Geremy Condra Not that

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