[issue7980] time.strptime not thread safe

2013-03-12 Thread William McBrine

William McBrine added the comment:

I'm still seeing this, in the 2.7.2 that comes with OS X 10.8.2.

--
nosy: +William.McBrine

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7980
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: RELEASED Python 3.0 final

2008-12-06 Thread William McBrine
On Fri, 05 Dec 2008 12:16:47 -0800, Fernando H. Sanches wrote:

 I agree that the tab/space thing should be changed. Would it be too hard
 to make the parser see if the indentation is consistent in the whole
 file?

*Something* has changed. I had a piece of code where, without realizing 
it, I had a tab mixed in with the spaces at the start of one line in a 
block. In 2.5, it worked, silently. In 3.0, I got an indentation error.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is not objects in Python?

2008-10-02 Thread William McBrine
On Wed, 01 Oct 2008 17:56:34 +0200, Boris Borcic wrote:

 42, for instance.
 
 Proof :
 
   42 is not object
 True
 
 QED

 isinstance(42, object)
True

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: like py2exe, but on a mac

2008-07-30 Thread William McBrine
On Tue, 29 Jul 2008 12:24:49 -0700, Russell E. Owen wrote:

 That is exactly what py2app does by default if you run py2app with the
 system python.

Thanks. I see that it* avoids the issue with Tk starting in the 
background that I get with Platypus, too.

In fact, it looks like the bundlebuilder module is adequate for my needs. 
It does put in a version-specific #! line, but if I change that to
#!/usr/bin/env python, the app still works, and it seems to me that it 
will work for any version of Python on OS 10.4, 10.5, and maybe 10.3.

* I still haven't actually tried it (py2app), since I realized that I 
already had bundlebuilder, but I'm assuming it's the same in this respect.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: like py2exe, but on a mac

2008-07-30 Thread William McBrine
On Wed, 30 Jul 2008 16:57:35 +, I wrote:

 [bundlebuidler] does put in a version-specific #! line, but if I change
 that to #!/usr/bin/env python, the app still works, and it seems to me
 that it will work for any version of Python on OS 10.4, 10.5, and maybe
 10.3.

Then again, I see now that it has more hardwired paths in the Python 
binary. Bah.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: like py2exe, but on a mac

2008-07-28 Thread William McBrine
On Mon, 28 Jul 2008 19:51:26 +0200, Tommy Nordgren wrote:

 There is Platypus, a general open source program to wrap a script
 in an Macintosh (GUI) Application.

Thanks. I tried Platypus, and it's close to what I want. But I still 
can't seem to get rid of the small Console window that pops up behind 
my Tkinter app.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: Questions on 64 bit versions of Python

2008-07-28 Thread William McBrine
On Sun, 27 Jul 2008 20:31:07 +0200, Martin v. Löwis wrote:

 Originally, AMD called it x86-64, and later renamed it to AMD64. Intel
 originally implemented it under the name EM64T (for Extended Memory 64
 Technology), and now calls the architecture Intel 64.

I hadn't heard Intel 64 before. That's a bit nervy, isn't it? Plus it 
seems to conflict with their own use of IA-64 (Intel Architecture 64) 
for the Itanium (vs. IA-32 for traditional x86).

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list

Re: like py2exe, but on a mac

2008-07-28 Thread William McBrine
On Mon, 28 Jul 2008 21:09:10 +0200, Tommy Nordgren wrote:

 Try setting the Output popup menu to 'None'

That was the first thing I did.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: like py2exe, but on a mac

2008-07-28 Thread William McBrine
On Mon, 28 Jul 2008 15:18:43 -0400, Kevin Walzer wrote:

 Add this call to your Python script somewhere (modify as needed):
 
 try:
  self.tk.call('console', 'hide')
  except TclError:
  pass

Ah, yes! Thanks.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: like py2exe, but on a mac

2008-07-27 Thread William McBrine
On Sun, 13 Jul 2008 00:58:59 +0200, Python.Arno wrote:

 http://undefined.org/python/py2app.html

py2app bundles Python itself into the app, right? I wonder, is there no 
way to create an app bundle that relies on the existing installation of 
Python, since OS X already comes with Python? I have a tiny little 
program (~20k) that I'd like to make into an app bundle, if only to 
suppress the console window, and I'd rather not lump in the whole Python 
interpreter if I can avoid it.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can't get Python for Windows to run

2008-07-04 Thread William McBrine
On Fri, 04 Jul 2008 16:19:34 +0100, Tim Rowe wrote:

 pythonw.exe (that's the windows executable, right?)

python.exe and pythonw.exe are both Windows executables. There are no non-
Windows executables in a Python for Windows package.

python.exe is used for console apps or interactive sessions.

pythonw.exe suppresses the console window. You use it to launch GUI apps 
that don't need a console. You can't use it for an interactive session, 
and it makes no sense to start it without also specifying a Python 
program to run.

Python source files named with the .pyw extension are associated with 
pythonw.exe, while .py is associated with python.exe.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about tuples and list comprehensions

2008-06-25 Thread William McBrine
On Wed, 25 Jun 2008 16:02:52 -0700, John Machin wrote:

 Here's one approach (requires Python 2.5 or later):
 [(50 if x  50 else x, 50 if y  50 else y, 50 if z  50 else z) for
 (x, y, z) in source]

[(max(x, 50), max(y, 50), max(z, 50)) for (x, y, z) in source]

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: Learning Python: Code critique please

2008-06-22 Thread William McBrine
On Sun, 22 Jun 2008 08:44:25 -0500, Saul Spatz wrote:

 macoovacany wrote:
 http://macoovacany.wordpress.com/
 When I tried to run it, I got all kinds of syntax errors because of
 non-ASCII characters; namely, you have fancy left and right single and
 double quotes.

That's probably WordPress' doing.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Socket programming

2008-06-13 Thread William McBrine
On Fri, 13 Jun 2008 21:59:06 +0530, srinivasan srinivas wrote:

 I am going to do some socket related programming in Python. Before that,
 I wish to know the Gotchas of Python Scoket Programming.

The only gotcha I see is that you won't want to go back to doing it in C.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a simple python script to a simple windows executable

2008-06-12 Thread William McBrine
On Wed, 11 Jun 2008 12:25:29 -0700, geoffbache wrote:

 (1) py2exe. This is really for when python isn't installed on the remote
 user's machine, so it requires you to distribute a large amount of DLLs
 etc which are part of the python installation. A bit silly when I know
 that the remote user has python anyway.

If you know the target user has Python installed, why don't you just 
distribute the .pyw file? (Use .pyw instead of .py to avoid the extra 
console window.)

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Keeping focus with sequential Tkinter windows?

2008-05-27 Thread William McBrine
So, basically what I'm doing is this:

window1 = Tkinter.Tk()
...
window1.destroy()
...
window2 = Tkinter.Tk()

This works well in Linux and Mac OS X (and the PyGtk equivalent works on 
all platforms), but in Windows XP, the second window comes up without 
focus. (I have to click on it to focus it.) This is true even with no 
other windows on screen. I've tried window2.focus_set(), window2.lift(), 
etc., to no avail. What's the right way to do this?

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: Assignment and comparison in one statement

2008-05-24 Thread William McBrine
On Sat, 24 May 2008 13:12:13 +0200, Johannes Bauer wrote:

 char *tmp;
 tmp = fgets(buf, sizeof(buf), f);
 while (tmp) {
   printf(%s\n, buf);
   tmp = fgets(buf, sizeof(buf), f);
 }

I think a more Pythonic way to write this, in general, would be:

while (1) {
char *tmp = fgets(buf, sizeof(buf), f);
if (!tmp)
break;
printf(%s\n, buf);
}

In actual Python, that's:

while True:
buf = f.readline()
if not buf:
break
print buf

Yeah, it's longer than the traditional C way, but you don't need to have 
duplicate fgets() (or whatever) lines. On the plus side, you're less 
likely to get '=' and '==' accidentally swapped in Python.

For this specific example, it can be cut down much more:

for buf in f.readlines():
print buf

(BTW, all of the above result in doublespacing the original file, but 
that's what your C version was doing, so I kept it that way.)

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


When file-like objects aren't file-like enough for Windows

2008-03-16 Thread William McBrine
This is proving to be a recurring problem for me.

First, I used the save() method of a Python Imaging Library Image 
object to write directly to the wfile of a BaseHTTPRequestHandler- 
derived class:

pic.save(self.wfile, 'JPEG')

Worked great in Linux, barfed in Windows. I had to do this to get around 
it:

out = StringIO()
pic.save(out, 'JPEG')
encoded = out.getvalue()
self.wfile.write(encoded)

Now, I have a similar problem with subprocess.Popen... The code that 
works in Linux looks like this:

source = urllib.urlopen(url)
child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=source)
try:
shutil.copyfileobj(child.stdout, self.wfile)
except:
kill(child.pid)

But wfile isn't the problem this time; instead, it's the source:

...
child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=source)
File C:\Python25\lib\subprocess.py, line 586, in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
File C:\Python25\lib\subprocess.py, line 698, in _get_handles
p2cread = msvcrt.get_osfhandle(stdin.fileno())
IOError: [Errno 9] Bad file descriptor 

How can I get around this, short of resorting to copying all of the input 
before passing it to the child?

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removal of element from list while traversing causes the next element to be skipped

2008-02-01 Thread William McBrine
On Wed, 30 Jan 2008 06:07:45 -0800, cokofreedom wrote:

 Anyone else noticed that the OP has not actually replied to any of the
 suggestions...

Sorry. I was just fascinated at the turns it was taking. But the first 
answer was fine for me:

for name in apps[:]:
  etc.

Thanks all.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
-- 
http://mail.python.org/mailman/listinfo/python-list


Removal of element from list while traversing causes the next element to be skipped

2008-01-29 Thread William McBrine
Look at this -- from Python 2.5.1:

 a = [1, 2, 3, 4, 5]
 for x in a:
... if x == 3:
... a.remove(x)
... print x
... 
1
2
3
5
 a
[1, 2, 4, 5]


Sure, the resulting list is correct. But 4 is never printed during the 
loop!

What I was really trying to do was this:

apps = [name for name in os.listdir(ROOT) if 
os.path.isdir(os.path.join(ROOT, name))]

apptitles = {}

for name in apps:
try:
app = __import__(name)
except:
apps.remove(name)
else:
apptitles[name] = getattr(app, 'TITLE', name.title())

which worked fine, until I actually had a directory with no module in it. 
Then that directory was correctly removed from the list, but the _next_ 
one was skipped, so its title was never assigned, which caused problems 
later in the program.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Big-endian binary data to/from Python ints?

2007-12-27 Thread William McBrine
On Wed, 26 Dec 2007 16:50:53 -0800, Dennis Lee Bieber wrote:

 your code might (I've not actually checked it) be incorrect if ported
 to another machine.

Nope. :-)

 If the problem is that you have the four bytes as a character string,
 use the struct module to interpret it as a binary integer and then feed
 the results to the above functions, followed by using struct to convert
 back to a string representation.
 
   Heck, looking at struct, it already has a format modifier for
 net-oriented... (assuming unsigned 32-bit integer)
 
   pinteger = struct.unpack(!I, netstring[0:4])[0]
 and
   netstring = struct.pack(!I, pinteger)

Thanks, that seems to be what I was looking for.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Performance on local constants?

2007-12-26 Thread William McBrine
Thanks for all the answers on this. (And, sorry the lousy Subject line; I 
couldn't think of a better one.)

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
-- 
http://mail.python.org/mailman/listinfo/python-list


Big-endian binary data to/from Python ints?

2007-12-26 Thread William McBrine
Here are a couple of functions that I feel stupid for having written. 
They work, and they're pretty straightforward; it's just that I feel like 
I must be missing an easier way to do this...

def net_to_int(numstring):
Convert a big-endian binary number, in the form of a string of
arbitrary length, to a native int.

num = 0
for i in numstring:
num *= 256
num += ord(i)
return num

def int_to_net(num):
Convert a native int to a four-byte big-endian number, in the form
of a string.

numstring = ''
for i in xrange(4):
numstring = chr(num % 256) + numstring
num /= 256
return numstring

The situation: I'm getting a four-byte packet from a socket that consists 
of a big-endian 32-bit integer. (It specifies the length of the data that 
follows.) I have to send the same thing in reply. send() and recv() work 
with strings... I'm familiar with ntohl() and htonl(), but those expect/ 
return integers.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
-- 
http://mail.python.org/mailman/listinfo/python-list


Performance on local constants?

2007-12-22 Thread William McBrine
Hi all,

I'm pretty new to Python (a little over a month). I was wondering -- is 
something like this:

s = re.compile('whatever')

def t(whatnot):
return s.search(whatnot)

for i in xrange(1000):
print t(something[i])

significantly faster than something like this:

def t(whatnot):
s = re.compile('whatever')
return s.search(whatnot)

for i in xrange(1000):
result = t(something[i])

? Or is Python clever enough to see that the value of s will be the same 
on every call, and thus only compile it once?

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
-- 
http://mail.python.org/mailman/listinfo/python-list