Re: chunking a long string?

2013-11-09 Thread Chris Angelico
On Sun, Nov 10, 2013 at 1:37 AM, Roy Smith r...@panix.com wrote: In article mailman.2283.1383985583.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: Some languages [intern] automatically for all strings, others (like Python) only when you ask for it. What does only when

Re: datetime question

2013-11-09 Thread Chris Angelico
On Sat, Nov 9, 2013 at 9:29 AM, Grant Edwards invalid@invalid.invalid wrote: It's that global newline shortage again. Just because a few people get killed in a newline mine they all go on strike... It's a conspiracy! The government kills a few miners (with their contrail mind-control stuffo)

Re: chunking a long string?

2013-11-09 Thread Chris Angelico
On Sun, Nov 10, 2013 at 2:21 AM, Roy Smith r...@panix.com wrote: But, you missed the point of my question. You said that Python does this only when you ask for it. That implies it never interns strings if you don't ask for it, which is clearly not true: $ python Python 2.7.1 (r271:86832,

Re: Sandboxing Python [was Re: New user's initial thoughts / criticisms of Python]

2013-11-09 Thread Chris Angelico
On Sun, Nov 10, 2013 at 2:25 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sun, 10 Nov 2013 01:27:11 +1100, Chris Angelico wrote: I was trying to sandbox CPython and run untrusted scripts while stopping them from accessing the OS or file system. It's basically impossible

Re: chunking a long string?

2013-11-09 Thread Chris Angelico
On Sun, Nov 10, 2013 at 2:37 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I think that Chris is wrong about Python only interning strings if you explicitly ask for it. I recall that Python will (may?) automatically intern strings which look like identifiers (e.g. spam but

Re: To whoever hacked into my Database

2013-11-09 Thread Chris Angelico
On Sun, Nov 10, 2013 at 2:32 AM, Antoon Pardon antoon.par...@rece.vub.ac.be wrote: And i had until i made some new changes last night, which i think i have corrected now as we speak. Continuing the arrogance. Just to put that in perspective, by the way: *EVERYONE* writes vulnerable code.

Re: datetime question

2013-11-09 Thread Chris Angelico
On Sun, Nov 10, 2013 at 2:39 AM, Gene Heskett ghesk...@wdtv.com wrote: Ya know, folks like Nick would have me signing off. Fortunately there are kill files. But the backscatter he creates I am still forced to read, or more usually skip. Then one of you frustrated standup comics comes along,

Languages for different purposes (was Re: New user's initial thoughts / criticisms of Python)

2013-11-09 Thread Chris Angelico
On Sun, Nov 10, 2013 at 8:21 AM, Mark Janssen dreamingforw...@gmail.com wrote: I'd be interested to hear your thoughts on where the field of computer languages is heading, and how that affects the choice of languages for building web sites. Well, there aren't that many groupings towards

Re: New user's initial thoughts / criticisms of Python

2013-11-09 Thread Chris Angelico
On Sun, Nov 10, 2013 at 9:44 AM, Jonathan jtc...@gmail.com wrote: In pythonic syntax: select expression0: case case expression,[case expression],: which is equivalent to: elif expression0 = expression1: which is equivalent to: elif expression0 binary-operator Small clarification: It's

Re: Languages for different purposes (was Re: New user's initial thoughts / criticisms of Python)

2013-11-09 Thread Chris Angelico
On Sun, Nov 10, 2013 at 11:41 AM, Roy Smith r...@panix.com wrote: On 09/11/2013 22:58, Chris Angelico wrote: * Some languages are just fundamentally bad. I do not recommend ever writing production code in Whitespace, Ook, or Piet. One of the worst coding experiences I ever had was trying

Re: New user's initial thoughts / criticisms of Python

2013-11-09 Thread Chris Angelico
On Sun, Nov 10, 2013 at 11:50 AM, MRAB pyt...@mrabarnett.plus.com wrote: On 09/11/2013 22:44, Jonathan wrote: In pythonic syntax: select expression0: case case expression,[case expression],: case else: [snip] It's more likely that the cases would be indented the

Re: Languages for different purposes (was Re: New user's initial thoughts / criticisms of Python)

2013-11-09 Thread Chris Angelico
On Sun, Nov 10, 2013 at 12:05 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: I'd forgotten I'd used Monk back around 1999/2000. I couldn't remember much about it so just looked it up here http://docs.oracle.com/cd/E18867_01/SRE/Monk_Reference_SRE.pdf, not sure if it's double or triple yuck.

Re: chunking a long string?

2013-11-10 Thread Chris Angelico
On Sun, Nov 10, 2013 at 5:39 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sun, 10 Nov 2013 09:14:28 +1100, Chris Angelico wrote: And as is typical of python-list, it's this extremely minor point that became the new course of the thread - You say that as if it were

Re: datetime question

2013-11-10 Thread Chris Angelico
On Sun, Nov 10, 2013 at 11:55 AM, Gene Heskett ghesk...@wdtv.com wrote: On Saturday 09 November 2013 19:52:52 Chris Angelico did opine: :) Don't just thank me, Grant and Roy were key to it too - and the whole there's no shortage of newlines thing started with Steven D'Aprano (I think

Re: New user's initial thoughts / criticisms of Python

2013-11-10 Thread Chris Angelico
On Sun, Nov 10, 2013 at 7:47 PM, Jorgen Grahn grahn+n...@snipabacken.se wrote: On Sat, 2013-11-09, Chris Angelico wrote: On Sun, Nov 10, 2013 at 12:08 AM, John von Horn j@btinternet.com wrote: ... * Why not allow floater=float(int1/int2) - rather than floater=float (int1)/float(int2

Re: my favorite line of py code so far

2013-11-10 Thread Chris Angelico
On Sun, Nov 10, 2013 at 7:57 PM, Peter Cacioppi peter.cacio...@gmail.com wrote: Chris said : I think map is fine if you can use a named function, but if you can't come up with a descriptive name for what you're doing, a comprehension is probably better (as it'll have the code right there).

Re: New user's initial thoughts / criticisms of Python

2013-11-10 Thread Chris Angelico
On Sun, Nov 10, 2013 at 10:39 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Sun, Nov 10, 2013 at 2:22 AM, Chris Angelico ros...@gmail.com wrote: JavaScript has magic around the dot and function-call operators, as I mentioned earlier. Lots of other languages have some little quirk somewhere

Re: New user's initial thoughts / criticisms of Python

2013-11-10 Thread Chris Angelico
On Mon, Nov 11, 2013 at 4:12 AM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: -123 .bit_length() -7 No parens needed if a space precedes the . Heh! I would call that an inferior alternative to the parentheses though; it's so unusual to put a space before the dot that I wouldn't

Re: To whoever hacked into my Database

2013-11-10 Thread Chris Angelico
On Mon, Nov 11, 2013 at 7:41 AM, Chris “Kwpolska” Warrick kwpol...@gmail.com wrote: On Nov 10, 2013 9:01 PM, Rod Person rodper...@rodperson.com wrote: Tortoise? What's a tortoise? Is that a real question? If yes, then it's an animal, similar to a turtle. Ask Google or Wikipedia for more

Re: The narcissism of small code differences

2013-11-11 Thread Chris Angelico
On Mon, Nov 11, 2013 at 8:25 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 11/11/2013 06:50, Rick Johnson wrote: In a nutshell the author attempts to plead for the longevity of old code bases simply on the basis of his assertion that old code bases are less buggy and contain

Re: Languages for different purposes (was Re: New user's initial thoughts / criticisms of Python)

2013-11-11 Thread Chris Angelico
On Mon, Nov 11, 2013 at 8:28 PM, wxjmfa...@gmail.com wrote: * Some languages are just fundamentally bad. The flexible string representation is a perfect exemple. Wow. A new low for you, jmf... comparing PEP 393 to Ook?!? In fact, with such a mechanism, it is even impossible to write an

Re: New user's initial thoughts / criticisms of Python

2013-11-11 Thread Chris Angelico
On Mon, Nov 11, 2013 at 9:09 PM, lorenzo.ga...@gmail.com wrote: Regarding the select statement, I think the most Pythonic approach is using dictionaries rather than nested ifs. Supposing we want to decode abbreviated day names (mon) to full names (Monday): That's an obvious mapping,

Re: Getting globals of the caller, not the defining module

2013-11-11 Thread Chris Angelico
On Mon, Nov 11, 2013 at 10:25 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: But since spam is supposed to introspect as much information as possible, I don't really want to do that. What (if anything) are my other options? You're playing with introspection, so I'd look at

Re: New user's initial thoughts / criticisms of Python

2013-11-11 Thread Chris Angelico
On Mon, Nov 11, 2013 at 10:17 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Mon, 11 Nov 2013 21:39:27 +1100, Chris Angelico wrote: denormalizes it into a lookup table by creating 70 entries quoting the first string, 15 quoting the second, 5, and 10, respectively. Ewww

Re: New user's initial thoughts / criticisms of Python

2013-11-11 Thread Chris Angelico
On Mon, Nov 11, 2013 at 10:53 PM, Robert Kern robert.k...@gmail.com wrote: Heh. I've done pretty much exactly the same thing to implement an engine[1] to draw from the random tables on Abulafia[2] which have nearly the same structure. It scales up reasonably well beyond d100s. It's certainly

Re: datetime question

2013-11-11 Thread Chris Angelico
On Tue, Nov 12, 2013 at 1:14 AM, Roy Smith r...@panix.com wrote: We've got a data supplier who (for reasons I cannot fathom), runs their network in local time. Every time we talk to them about problems, it's a mess just trying to figure out what time we're talking about. We say, we saw a

Re: New user's initial thoughts / criticisms of Python

2013-11-11 Thread Chris Angelico
On Tue, Nov 12, 2013 at 7:50 AM, Joshua Landau jos...@landau.ws wrote: The obvious way to me is a binary search: Which makes an O(log n) search where I have an O(1) lookup. The startup cost of denormalization doesn't scale, so when the server keeps running for two years or more, it's definitely

Re: Creating a function for a directory

2013-11-11 Thread Chris Angelico
On Tue, Nov 12, 2013 at 9:26 AM, Matt mattgrav...@gmail.com wrote: So I want to take the file, desktop/test.txt and write it to desktop/newfolder/test.txt. I tried the below script, and it gave me: IOError: [Errno 2] No such file or directory: 'desktop/%s.txt'. Any suggestions would be

Re: Creating a function for a directory

2013-11-11 Thread Chris Angelico
On Tue, Nov 12, 2013 at 9:51 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: On Monday, November 11, 2013 4:26:46 PM UTC-6, Matt wrote: So I want to take the file, desktop/test.txt and write it to desktop/newfolder/test.txt. I tried the below script, and it gave me: IOError: [Errno 2] No

Re: 'isimmutable' and 'ImmutableNester'

2013-11-11 Thread Chris Angelico
On Tue, Nov 12, 2013 at 11:17 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Mon, 11 Nov 2013 12:55:56 -0800, Ned Batchelder wrote: On Monday, November 11, 2013 3:47:45 PM UTC-5, Frank-Rene Schäfer wrote: I prepared a PEP and was wondering what your thoughts are about it:

Re: Creating a function for a directory

2013-11-11 Thread Chris Angelico
On Tue, Nov 12, 2013 at 9:44 AM, Joel Goldstick joel.goldst...@gmail.com wrote: Sorry for incorect answer. Those guys nailed it Your answer wasn't incorrect, because it didn't give any false information. Bob and I saw the problem itself and gave advice, but you gave useful general advice on how

Re: Where to handle try-except - close to the statement, or in outer loop?

2013-11-11 Thread Chris Angelico
On Tue, Nov 12, 2013 at 12:34 PM, Victor Hooi victorh...@gmail.com wrote: Would I wrap all of the calls in a try-except block? try: my_pet.feed() my_pet.shower() except IOError as e: # Do something to handle exception? It really depends more on how you go

Re: datetime question

2013-11-11 Thread Chris Angelico
On Tue, Nov 12, 2013 at 12:59 PM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: Of course, I'm spoiled... My /watch/ has a dial for UTC, along with one for 24-hour indication (one hand, range 1 to 24) Heh. Mine doesn't, so I bought myself a second watch and set it to UTC. So my left

Re: PyMyth: Global variables are evil... WRONG!

2013-11-11 Thread Chris Angelico
On Tue, Nov 12, 2013 at 3:46 PM, Rick Johnson rantingrickjohn...@gmail.com wrote: But python modules can't be interfaces because interfaces should protect internal data, prevent external forces from meddling with internal state (EXCEPT via the rules of a predefined contract), hide dirty

Re: Creating a function for a directory

2013-11-11 Thread Chris Angelico
On Tue, Nov 12, 2013 at 4:42 PM, Rick Johnson rantingrickjohn...@gmail.com wrote: On Monday, November 11, 2013 5:11:52 PM UTC-6, Chris Angelico wrote: On Tue, Nov 12, 2013 at 9:51 AM, Rick Johnson 1. i believe win32 file paths require a qualifying volume letter. They do not; omitting

Re: 'isimmutable' and 'ImmutableNester'

2013-11-11 Thread Chris Angelico
On Tue, Nov 12, 2013 at 6:01 PM, Frank-Rene Schäfer fsch...@gmail.com wrote: A tuple is immutable but it may contain mutable objects. In larger hierarchies of objects it may become less obvious whether down the lines, there is some mutable object somewhere in the data tree. One can define a

Re: datetime question

2013-11-11 Thread Chris Angelico
On Tue, Nov 12, 2013 at 6:25 PM, alex23 wuwe...@gmail.com wrote: On 12/11/2013 2:49 PM, Grant Edwards wrote: Don't forget that there are also some differences between American and Imperial whitespace. Since it's ASCII whitespace, you should probably assume American... sys.getsizeof(' ')

Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Chris Angelico
On Tue, Nov 12, 2013 at 8:12 PM, Frank-Rene Schäfer fsch...@gmail.com wrote: (1) hash()-ability != immutability (!) Proof: class X: def __hash__(self): return 0 x == y != y == x Proof: class X: def __eq__(self,other): return True class Y: def __eq__(self,other): return False

Re: To whoever hacked into my Database

2013-11-12 Thread Chris Angelico
On Tue, Nov 12, 2013 at 8:34 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 12/11/2013 05:21, Gregory Ewing wrote: Ned Batchelder wrote: I don't know how best to make things better overall. I know that overlooking Nikos' faults won't do it. If everyone who reached the point where

Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Chris Angelico
On Tue, Nov 12, 2013 at 8:39 PM, Frank-Rene Schäfer fsch...@gmail.com wrote: All you've done is proven that you can subvert things. By fiddling with __hash__, __eq__, and so on, you can make sets and dicts behave very oddly. Means nothing. To the contrary, it means everything about what

Re: datetime question

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 1:12 AM, Ferrous Cranus nikos.gr...@gmail.com wrote: Joel i must thank you for your help. I cannot believe it was so simple. Tnhe server is self aware of its location so why use utcnow() + timedelte( some_digit_here ) when you can just use just now() Did you ever go

Re: PyMyth: Global variables are evil... WRONG!

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 1:32 AM, Alister alister.w...@ntlworld.com wrote: As an analogy music has may general rules that musicians are wise to follow. Some pieces of music that break these rules are great because they have broken the rules but most are not. those that are great are great

Re: datetime question

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 6:14 AM, Joel Goldstick joel.goldst...@gmail.com wrote: In the US, the state of Indiana is really weird. Three separate time zone areas, that don't all flip in the same way. See this for TZ hell: http://en.wikipedia.org/wiki/Indiana_time_zones Timezones are one of

Re: Some python newb help please?

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 9:27 AM, lrwarre...@gmail.com wrote: I'm not quite sure what you mean by that. it was on that pastebin link. I'll post it again here though. it's no longer than half a page. Inline means what you did in this post. Out-of-line means providing us with a link to where the

Re: Basic Python Questions - Oct. 31, 2013

2013-11-12 Thread Chris Angelico
On Tue, Nov 12, 2013 at 9:21 PM, E.D.G. edgrs...@ix.netcom.com wrote: The point is, when people want to make some computer program available for use by others around the world they might want to circulate a version of their program that has such a simple format that anyone can understand

Re: using print() with multiprocessing and pythonw

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 7:22 AM, Isaac Gerg isaac.g...@gergltd.com wrote: Thanks for the reply Bill. The problem is the text i am getting is from a python warning message, not one of my own print() function calls. Since sys.stdout is just an object, you could replace it with something that

Re: [Python-Dev] The pysandbox project is broken

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 8:16 AM, Victor Stinner victor.stin...@gmail.com wrote: In 2010, a developper called Tav wrote a sandbox called safelite.py: the sandbox hides sensitive attributes to separate a trusted namespace and an untrusted namespace. Ha, I come full circle. This was the exact

Re: Some python newb help please?

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 10:04 AM, lrwarre...@gmail.com wrote: Thanks a lot! I'll try this out! Sorry to everyone else whose eyes I made bleed. I've never used a newsgroup before...still not really sure what they are. Found this through a google search :\ There's an easy fix. Go to this

Re: datetime question

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 11:30 AM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Tue, 12 Nov 2013 13:02:58 +1100, Chris Angelico ros...@gmail.com declaimed the following: On Tue, Nov 12, 2013 at 12:59 PM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: Of course, I'm spoiled... My

Re: Flexible string representation, unicode, typography, ...

2012-08-28 Thread Chris Angelico
On Wed, Aug 29, 2012 at 12:42 PM, rusi rustompm...@gmail.com wrote: Clearly there are 3 string-engines in the python 3 world: - 3.2 narrow - 3.2 wide - 3.3 (flexible) How difficult would it be to giving the choice of string engine as a command-line flag? This would avoid the nuisance of

Re: Flexible string representation, unicode, typography, ...

2012-08-29 Thread Chris Angelico
On Wed, Aug 29, 2012 at 9:40 PM, wxjmfa...@gmail.com wrote: For a given coding scheme, all code points/characters are equivalent. Expecting to handle a sub-range in a coding scheme without shaking that coding scheme is impossible. Not all codepoints are equally likely. That's the whole point

Re: Flexible string representation, unicode, typography, ...

2012-08-29 Thread Chris Angelico
On Thu, Aug 30, 2012 at 1:43 AM, wxjmfa...@gmail.com wrote: If Python has found a new way to cover the set of the Unicode characters, why not proposing it to the Unicode consortium? Python's open source. If some other language wants to borrow the idea, they can look at the code, or

Re: Flexible string representation, unicode, typography, ...

2012-08-30 Thread Chris Angelico
On Thu, Aug 30, 2012 at 6:51 PM, wxjmfa...@gmail.com wrote: Pick up a random text and see the probability this text match the most optimized case 1 char / 1 byte, practically never. Only if you talk about a huge document. Try, instead, every string ever used in a Python script. Practically

Re: Beginners question

2012-08-30 Thread Chris Angelico
On Thu, Aug 30, 2012 at 9:54 PM, boltar2003@boltar.world wrote: What sort of object is posix.stat_result? Its not a dictionary or list or a class object as far as I can tell. Thanks for any help. There's some cool things you can do here. (Note that I'm testing this on a Windows box, so it's

Re: Beginners question

2012-08-30 Thread Chris Angelico
On Thu, Aug 30, 2012 at 10:50 PM, boltar2003@boltar.world wrote: On Thu, 30 Aug 2012 13:14:57 +0100 MRAB pyt...@mrabarnett.plus.com wrote: What don't you ask Python? I'm sure you'' get something like this: type(s) class 'posix.stat_result' Umm , no I don't. type(s) type

Re: get return or locals from exec str in environment

2012-08-30 Thread Chris Angelico
On Fri, Aug 31, 2012 at 8:11 AM, lucas sjluk...@gmail.com wrote: and i can see my executed function in there as a type function, and local and global vars, but i can not access or find harry or rtn the variables within the function lucas53. i do not know how to access the local variables

Re: get return or locals from exec str in environment

2012-08-30 Thread Chris Angelico
On Fri, Aug 31, 2012 at 8:25 AM, lucas sjluk...@gmail.com wrote: Far as I can see, you never actually called that function anywhere. ChrisA doesn't the exec command call the function? (Side point: You don't have to post to both comp.lang.python and python-list - they mirror each other.) What

Re: get return or locals from exec str in environment

2012-08-30 Thread Chris Angelico
On Fri, Aug 31, 2012 at 9:54 AM, lucas sjluk...@gmail.com wrote: oh, yeah that was perfect. got it working and it is graceful too. sorry about the double post, i thought i was only posting to this one. Hehe, you're still posting to both. I don't see the duplicates myself, but I'm sure others

Re: to know binary

2012-08-31 Thread Chris Angelico
On Sat, Sep 1, 2012 at 2:15 PM, contro opinion contropin...@gmail.com wrote: there is a only line in the file nanmed test: 1234 when i open it whit xxd xxd test what i get is : 000: 3132 3334 0a 1234. can you explain it ? I would explain it as a file with

Re: interfacing with x86_64 assembler

2012-09-01 Thread Chris Angelico
On Sun, Sep 2, 2012 at 10:10 AM, John Ladasky john_lada...@sbcglobal.net wrote: I haven't seen this joke on the Net in years, does anyone still remember it? C combines the power of assembly language with the readability and maintainability of assembly language. Seen it, and it has validity.

Re: Changing a Value in List of lists

2012-09-02 Thread Chris Angelico
On Sun, Sep 2, 2012 at 7:44 PM, Rishabh Dixit rishabhdixi...@gmail.com wrote: Hi all, I have a doubt regarding how the list work in following case- ls=[[0]*5]*5 ls[1][1]+=1 ls [[0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0]] Here, according to me

Re: newbie ``print`` question

2012-09-02 Thread Chris Angelico
On Mon, Sep 3, 2012 at 7:18 AM, gwhite gwh...@ti.com wrote: Thanks again, Terry. There is a lot to the language, I am finding out. I am a HW engineer, not really a programmer. Python seems a lot more sophisticated than MATLAB. I'm kinda thinking `write` is likely to be a little more stable

Re: newbie ``print`` question

2012-09-02 Thread Chris Angelico
On Mon, Sep 3, 2012 at 9:20 AM, gwhite gwh...@ti.com wrote: I guess you're saying 3.x will just ignore: from __future__ import print_function I'll risk being silly, and thus ask: but what if when I get to 3.x there is no __future__, as it is now present? Do I need to strip out the line?

Re: simple client data base

2012-09-03 Thread Chris Angelico
On Tue, Sep 4, 2012 at 12:12 AM, Mark R Rivet markrri...@aol.com wrote: I have been reading about lists, tuples, and dictionary data structures in python and I am confused as to which would be more appropriate for a simple database. I think you're looking at this backwards. A database is for

Re: Comparing strings from the back?

2012-09-03 Thread Chris Angelico
On Tue, Sep 4, 2012 at 11:54 AM, Roy Smith r...@panix.com wrote: I'm wondering if it might be faster to start at the ends of the strings instead of at the beginning? I'm also not sure how this work with all the possible UCS/UTF encodings. With some of them, you may get the encoding semantics

Re: Comparing strings from the back?

2012-09-04 Thread Chris Angelico
On Wed, Sep 5, 2012 at 2:32 AM, Johannes Bauer dfnsonfsdu...@gmx.de wrote: How do you arrive at that conclusion? When comparing two random strings, I just derived n = (256 / 255) * (1 - 256 ^ (-c)) where n is the average number of character comparisons and c. The rationale as follows: The

Re: The opener parameter of Python 3 open() built-in

2012-09-04 Thread Chris Angelico
On Wed, Sep 5, 2012 at 5:16 AM, Terry Reedy tjre...@udel.edu wrote: io.open depends on a function the returns an open file descriptor. opener exposes that dependency so it can be replaced. I skimmed the bug report comments but didn't find an answer to this: Why not just monkey-patch? When a

Re: How to tell people to ask questions the smart way

2012-09-04 Thread Chris Angelico
On Wed, Sep 5, 2012 at 9:28 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 05/09/2012 00:05, Ben Finney wrote: Look there: http://www.catb.org/esr/faqs/smart-questions.html#forum The “how to ask question the smart way” essay is not a blunt instrument for beating people over the head

Re: Comparing strings from the back?

2012-09-05 Thread Chris Angelico
On Wed, Sep 5, 2012 at 6:29 PM, Peter Otten __pete...@web.de wrote: comparing every pair in a sample of 1000 8-char words taken from '/usr/share/dict/words' head 1: 477222 2: 18870 ** ... Not understanding this. What are the

Re: sockets,threads and interupts

2012-09-05 Thread Chris Angelico
On Wed, Sep 5, 2012 at 10:54 PM, Ramchandra Apte maniandra...@gmail.com wrote: At least on Linux, if you kill a process using sockets, it takes about 10 seconds for socket to be closed. A program should try to close all resources. OS'es may take a long time to close a unclosed socket

Re: why did the WindowsError occur?

2012-09-05 Thread Chris Angelico
On Wed, Sep 5, 2012 at 10:51 PM, Ramchandra Apte maniandra...@gmail.com wrote: On Wednesday, 5 September 2012 13:21:58 UTC+5:30, Mark Lawrence wrote: Because you've done something wrong. If you'd like to tell us what you've done to find out where the problem is, we are far more likely to

Re: Python Interview Questions

2012-09-05 Thread Chris Angelico
On Thu, Sep 6, 2012 at 12:21 AM, Peter Otten __pete...@web.de wrote: charvigro...@gmail.com wrote: Finally I have decided to put best interview question and answers. Please visit http://***/web/CorePython/ for core python and http://***/web/PythonAdvanced/ for advanced python Hm, are you a

Re: Python Interview Questions

2012-09-05 Thread Chris Angelico
On Thu, Sep 6, 2012 at 12:34 AM, Chris Angelico ros...@gmail.com wrote: However, this strikes me as encouraging some really inefficient code, like iterating over all the rows in a table with N+1 queries (one to get the length, then a separate query for each row). Huh. And then I scroll down

Re: Python Interview Questions

2012-09-05 Thread Chris Angelico
On Thu, Sep 6, 2012 at 1:22 AM, Ian Kelly ian.g.ke...@gmail.com wrote: The lack of an ORDER BY is the least of the problems with that SQL. He's also using LIMIT without OFFSET, so the only thing that the 'item' argument changes is how many rows are returned (all but one of which are ignored),

Re: Python Interview Questions

2012-09-05 Thread Chris Angelico
On Thu, Sep 6, 2012 at 2:40 AM, Ian Kelly ian.g.ke...@gmail.com wrote: On Wed, Sep 5, 2012 at 9:34 AM, Chris Angelico ros...@gmail.com wrote: On Thu, Sep 6, 2012 at 1:22 AM, Ian Kelly ian.g.ke...@gmail.com wrote: The lack of an ORDER BY is the least of the problems with that SQL. He's also

Re: is implemented with id ?

2012-09-06 Thread Chris Angelico
On Thu, Sep 6, 2012 at 6:26 PM, Ramchandra Apte maniandra...@gmail.com wrote: the is statement could be made into a function It's not a statement, it's an operator; and functions have far more overhead than direct operators. There's little benefit in making 'is' into a function, and high cost;

Re: is implemented with id ?

2012-09-06 Thread Chris Angelico
On Thu, Sep 6, 2012 at 7:34 PM, Duncan Booth duncan.booth@invalid.invalid wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: But at any moment, any object has a specific location, and no other object can have that same location. Two objects cannot both be at the same memory

Re: Need help fixing this error please:NameError: global name is not defined

2012-09-06 Thread Chris Angelico
On Thu, Sep 6, 2012 at 8:45 PM, shaun shaun.wisema...@gmail.com wrote: CODE/// def databasebatchcall(self,tid, bid): con=cx_Oracle.connect('user/user...@odb4.dcc.company/ODB4TEST.COMPANY.COM') cur = con.cursor() cur.execute(SELECT *

Re: Need help fixing this error please:NameError: global name is not defined

2012-09-06 Thread Chris Angelico
On Thu, Sep 6, 2012 at 9:37 PM, shaun shaun.wisema...@gmail.com wrote: class StringCall: results=[] def databasebatchcall(self,termid, batchid): con = cx_Oracle.connect('user/user...@odb4.dcc.company.ie/ODB4TEST.COMPANY.IE') cur = con.cursor()

Re: Comparing strings from the back?

2012-09-06 Thread Chris Angelico
n Thu, Sep 6, 2012 at 10:13 PM, Roy Smith r...@panix.com wrote: In article 50485fca$0$29977$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: In any case, the *worst* case for string equality testing is certainly O(N) (every character must be

Re: Need help fixing this error please:NameError: global name is not defined

2012-09-06 Thread Chris Angelico
On Thu, Sep 6, 2012 at 10:07 PM, shaun shaun.wisema...@gmail.com wrote: Hi Chris, I'm changing it into multiple classes because the script is going to get much larger its more for maintainability reasons rather than functionality reasons. Doesn't necessarily have to be multiple

Re: Comparing strings from the back?

2012-09-06 Thread Chris Angelico
On Thu, Sep 6, 2012 at 11:37 PM, Johannes Bauer dfnsonfsdu...@gmx.de wrote: Not in my original post. If you read it again, you will clearly see that I was talking about purely random strings. And since you like to nitpick, I'll clarify further: I'm talking about bitstrings in which every bit

Re: A Python class

2012-09-06 Thread Chris Angelico
On Fri, Sep 7, 2012 at 3:30 AM, Terry Reedy tjre...@udel.edu wrote: On 9/6/2012 11:08 AM, Yves S. Garret wrote: I'd like to know if there are any online Python classes offered online from reliable institutions that you would recommend. Google 'online programming course python' for taught

Re: Function for examine content of directory

2012-09-06 Thread Chris Angelico
On Fri, Sep 7, 2012 at 12:56 AM, Tigerstyle laddosi...@gmail.com wrote: I'm trying to write a module containing a function to examine the contents of the current working directory and print out a count of how many files have each extension (.txt, .doc, etc.) If you haven't already, look into

Re: Accessing dll

2012-09-07 Thread Chris Angelico
On Fri, Sep 7, 2012 at 1:44 AM, Helpful person rrl...@yahoo.com wrote: FYI My Python version is 2.5.4 You may wish to upgrade, that's quite an old version. Unless something's binding you to version 2.x, I would strongly recommend migrating to 3.2 or 3.3. ChrisA --

Re: Division help in python

2012-09-07 Thread Chris Angelico
On Fri, Sep 7, 2012 at 10:53 PM, Ramyasri Dodla ramyasr...@gmail.com wrote: I am brand new to python. checking over basic stuff. I came across the problem while doing so. If any body aware of the problem, kindly respond me. 5/10 0 - 5/10 -1 The second case also should yield a 'zero' but

Re: Accessing dll

2012-09-08 Thread Chris Angelico
On Sat, Sep 8, 2012 at 3:27 AM, Helpful person rrl...@yahoo.com wrote: On Sep 7, 5:16 am, Chris Angelico ros...@gmail.com wrote: On Fri, Sep 7, 2012 at 1:44 AM, Helpful person rrl...@yahoo.com wrote: FYI My Python version is 2.5.4 You may wish to upgrade, that's quite an old version

Re: Is there a unique method in python to unique a list?

2012-09-08 Thread Chris Angelico
On Sun, Sep 9, 2012 at 3:43 PM, Token Type typeto...@gmail.com wrote: Is there a unique method in python to unique a list? thanks I don't believe there's a method for that, but if you don't care about order, try turning your list into a set and then back into a list. ChrisA --

Re: Is there a unique method in python to unique a list?

2012-09-09 Thread Chris Angelico
On Sun, Sep 9, 2012 at 4:29 PM, John H. Li typeto...@gmail.com wrote: However, if I don't put list(set(lemma_list)) to a variable name, it works much faster. Try backdenting that statement. You're currently doing it at every iteration of the loop - that's why it's so much slower. But you'll

Re: Is there a unique method in python to unique a list?

2012-09-09 Thread Chris Angelico
On Sun, Sep 9, 2012 at 11:44 PM, Token Type typeto...@gmail.com wrote: lemma_set.add(synset.lemma_names) That tries to add the whole list as a single object, which doesn't work because lists can't go into sets. There are two solutions, depending on what you want to do. 1) If you

Re: Comparing strings from the back?

2012-09-10 Thread Chris Angelico
On Tue, Sep 11, 2012 at 12:06 AM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 2012-09-10, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: What interning buys you is that s == t is an O(1) pointer compare if they are equal. But if s and t differ in the last character, __eq__

Re: Comparing strings from the back?

2012-09-10 Thread Chris Angelico
On Tue, Sep 11, 2012 at 12:43 AM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 2012-09-10, Oscar Benjamin oscar.j.benja...@gmail.com wrote: I haven't looked at the source but my understanding was precisely that there is an intern() bit and that not only the builtins module but all the

Re: Parsing ISO date/time strings - where did the parser go?

2012-09-10 Thread Chris Angelico
On Tue, Sep 11, 2012 at 7:46 AM, Rhodri James rho...@wildebst.demon.co.uk wrote: On Sun, 09 Sep 2012 13:14:30 +0100, Roy Smith r...@panix.com wrote: In article mailman.323.1346961101.27098.python-l...@python.org, Thomas Jollans t...@jollybox.de wrote: The ISO date/time format is dead simple

Re: Double sided double underscored variable names

2012-09-11 Thread Chris Angelico
On Wed, Sep 12, 2012 at 8:09 AM, Joshua Landau joshua.landau...@gmail.com wrote: If I were to use internal double-underscored names of the form __BS_internalname__, would the compiled code be able to assume that no-one had overwritten these variables and never will, even through modification

Re: Double sided double underscored variable names

2012-09-11 Thread Chris Angelico
On Wed, Sep 12, 2012 at 8:48 AM, Joshua Landau joshua.landau...@gmail.com wrote: Well, the problem is that a lot of collisions aren't predictable. locals()['foo'] = 2, for example. If it weren't for Python's annoying flexibility* I would definitely do something very close to what you suggest.

Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py

2012-09-11 Thread Chris Angelico
On Wed, Sep 12, 2012 at 5:13 AM, ruck john.ruckst...@gmail.com wrote: I'm not sure how I could have known that ntpath was already imported, since *I* didn't import it, but that was the key to my confusion. One way to find out is to peek at the cache. import sys sys.modules There are quite

Re: Double sided double underscored variable names

2012-09-11 Thread Chris Angelico
, Chris Angelico wrote: Inline functions? I like this idea. I tend to want them in pretty much any language I write in. What do you mean by in-line functions? If you mean what you literally say, I would answer that Python has that with lambda. But I guess you probably mean something more

Re: using text file to get ip address from hostname

2012-09-12 Thread Chris Angelico
On Thu, Sep 13, 2012 at 12:24 AM, dkato...@gmail.com wrote: i'm new to Python and i searched the web and could not find an answer for my issue. i need to get an ip address from list of hostnames which are in a textfile. This is sounding like homework, so I'll just give you a basic pointer.

Re: Guides for communicating with business accounting systems

2012-09-13 Thread Chris Angelico
On Fri, Sep 14, 2012 at 1:02 AM, Ben Finney ben+pyt...@benfinney.id.au wrote: What I want is pointers to a putative “What every programmer needs to know about storing commercial transactions for business accounting” general guide. Does that information already exist where I can point our team

Re: datetime

2012-09-13 Thread Chris Angelico
On Fri, Sep 14, 2012 at 1:19 AM, Max read...@hushmail.com wrote: Say, it's 09:00 now and Python makes it 11:30 *without* me having specified 11:30 but only given Python the 2h30m interval. Could you cheat and change the timezone offset? :D ChrisA --

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