Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-16 Thread Dan Stromberg
On Sat, Jul 16, 2011 at 4:52 PM, Cameron Simpson wrote: > Well to some extent because I share files with > another who uses 4 position tabs. Editing these is a real nightmare if > one uses 8 position tabs (as I do, the common editor/terminal default > these days). 8's been the default in pretty

Re: Ordered list question

2011-07-17 Thread Dan Stromberg
If you need "read everything, then sort once", then a dictionary (or collections.defaultdict if you require undefined's) and a single sort at the end is probably the way to go. If you truly need an ordered datastructure (because you're reading one element, using things sorted, reading another elem

Re: PEP 8 and extraneous whitespace

2011-07-21 Thread Dan Sommers
perator here But PEP 8 (under Other Recommendations) indicates spaces around the former but not the latter: key = val dict(key=val) We all know that there should be one-- and preferably only one --obvious way to do it. But what do we also know about foolish consistency? Dan -- D

Re: Strings show as brackets with a 'u'.

2011-07-23 Thread Dan Stromberg
It's probably a list containing a single unicode string. You can pull the first element from the list with n[0]. To print a unicode string in 2.x without the u stuff: print u'174'.encode('ISO-8859-1') On Sat, Jul 23, 2011 at 5:33 PM, goldtech wrote: > > Hi, > > >>> n > [u'174'] > >>> > > Prob

Re: Convert '165.0' to int

2011-07-23 Thread Dan Stromberg
On Sat, Jul 23, 2011 at 8:53 PM, Billy Mays wrote: > I'll probably get flak for this, but damn the torpedoes: > > def my_int(num): >import re >try: >m = re.match('^(-?[0-9]+)(.0)?$', num) >return int(m.group(1)) >except AttributeError: >#raise your own error, o

Re: I am fed up with Python GUI toolkits...

2011-07-23 Thread Dan Stromberg
On Wed, Jul 20, 2011 at 12:20 AM, Stefan Behnel wrote: > Steven D'Aprano, 20.07.2011 06:28: > > Python has a GIL. >>> >> >> Except for Jython, IronPython and PyPy. >> > > PyPy has a GIL, too. There's been talk of removing PyPy's GIL using transactional memory though. -- http://mail.python.org

Re: Refactor/Rewrite Perl code in Python

2011-07-24 Thread Dan Stromberg
On Sun, Jul 24, 2011 at 2:29 AM, Shashwat Anand wrote: > I am working with a huge codebase of Perl. > The code have zero documentation and zero unit-tests. > It seems like a huge hack. > My condolences. Er, actually, it sounds kind of fun. The underlying database schema is horrid. > So I want t

Re: Python for Web

2011-07-24 Thread Dan Stromberg
On Wed, Jun 15, 2011 at 5:11 AM, bruno.desthuilli...@gmail.com < bruno.desthuilli...@gmail.com> wrote: > On Jun 15, 9:50 am, sidRo wrote: > > Is Python only for server side? > > Is it a theoretical question or a practical one ?-) > > More seriously: except for the old proof-of-concept Grail brows

Re: Only Bytecode, No .py Files

2011-07-26 Thread Dan Stromberg
Another possibility: You could probably create a bunch of zero-length .py's that are older than the corresponding .pyc's. On Tue, Jul 26, 2011 at 8:19 AM, Eldon Ziegler wrote: > Is there a way to have the Python processor look only for bytecode > files, not .py files? We are seeing huge numbers o

Re: Selecting unique values

2011-07-26 Thread Dan Stromberg
Some good stuff has already been suggested. Another possibility is using a treap (not a duptreap but a treap): http://stromberg.dnsalias.org/~dstromberg/treap/ If you just need things unique'd once, the set + yield is an excellent option. If you need to keep things in order, but also need to ma

Re: seeking an example on C extension works in python 3.1.x or above

2011-07-26 Thread Dan Stromberg
You could try looking in the Python sources for examples. But using Cython is probably easier. On Tue, Jul 26, 2011 at 5:06 PM, wrote: > Hello, > I have been searching the example on C extension that works in python > 3.1.x ror above for long time. I tried the simple example given in > python

Re: seeking an example on C extension works in python 3.1.x or above

2011-07-26 Thread Dan Stromberg
BTW, I believe you need to compile your extension module(s) with the same compiler that was used to build the Python interpreter - otherwise there could be calling convention issues. On Tue, Jul 26, 2011 at 5:58 PM, Dan Stromberg wrote: > > You could try looking in the Python sourc

Re: shlex parsing

2011-07-27 Thread Dan Stromberg
I've not used the shlex module, but this feels more like an issue to address with a parser than for a lexical analyzer - or perhaps even both, since you're splitting on whitespace sometimes, and matching square brackets sometimes. I've used pyparsing for stuff a bit similar to this. Or here's a l

Re: shlex parsing

2011-07-27 Thread Dan Stromberg
You could probably use a recursive descent parser with the standard library. But if your management is OK with pyparsing, that might be easier, and a bit more clear as well. On Wed, Jul 27, 2011 at 2:08 PM, Karim wrote: > ** > > Thank you Dan for answering. > > I ended with t

Re: Approximate comparison of two lists of floats

2011-07-28 Thread Dan Stromberg
You'd probably better explain in English which things truly need to be compared with what. Right now, your first version is, I believe, an O(n^4) algorithm, which is extremely expensive, while your second (set-based) version appears to be O(n^3), which is quite a bit better, but still not stellar.

Re: Any suggestion to start more threads at the same time?

2011-07-28 Thread Dan Stromberg
You could try Jython. Other than that, you probably want a threadpool, or perhaps to try multiprocessing - but that much forking could be a problem as well. On Thu, Jul 28, 2011 at 2:07 PM, smith jack wrote: > I start many threads in order to make the work done, when the > concurrent number is

Re: python reading file memory cost

2011-08-01 Thread Dan Stromberg
A code snippet would work wonders in making sure you've communicated what you really need, or at least what you have now. But if you read the data into one big string, that'll be much more efficient than if you read it as a list of integers or even as a list of lines. Processing the data one chun

Re: Complex sort on big files

2011-08-01 Thread Dan Stromberg
Python 2.x, or Python 3.x? What are the types of your sort keys? If you're on 3.x and the key you need reversed is numeric, you can negate the key. If you're on 2.x, you can use an object with a __cmp__ method to compare objects however you require. You probably should timsort the chunks (which

Re: test systems

2011-08-01 Thread Dan Stromberg
I've been testing my Python code on these using virtualbox and/or physical machines (but mostly virtualbox): CentOS 6.0 Debian DragonflyBSD Fedora 15 FreeBSD Haiku R1 alpha 3 Linux Mint Minix OpenIndiana openSUSE Sabayon Scientific Linux 6 Slackware Solaris Express Ubuntu Windows 7 Sadly, I don't

Re: python reading file memory cost

2011-08-01 Thread Dan Stromberg
You could try forcing a garbage collection... On Mon, Aug 1, 2011 at 8:22 PM, Tony Zhang wrote: > Thanks! > > Actually, I used .readline() to parse file line by line, because I need > to find out the start position to extract data into list, and the end > point to pause extracting, then repeat u

Re: Complex sort on big files

2011-08-02 Thread Dan Stromberg
On Tue, Aug 2, 2011 at 3:25 AM, Alistair Miles wrote: > Hi Dan, > > Thanks for the reply. > > On Mon, Aug 1, 2011 at 5:45 PM, Dan Stromberg wrote: > > > > Python 2.x, or Python 3.x? > > Currently Python 2.x. > So it sounds like you may want to move this code

Re: Hardlink sub-directories and files

2011-08-02 Thread Dan Stromberg
On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans wrote: > On 02/08/11 11:32, loial wrote: > > I am trying to hardlink all files in a directory structure using > > os.link. > > > > However I do not think it is possible to hard link directories ? > That is pretty true. I've heard of hardlinked dire

Re: how to sort a hash list without generating a new object?

2011-08-02 Thread Dan Stromberg
On Tue, Aug 2, 2011 at 5:53 PM, Chris Rebert wrote: > On Tue, Aug 2, 2011 at 11:02 AM, smith jack wrote: > > the source code is as follows > > > > x={} > > x['a'] = 11 > > x['c'] = 19 > > x['b'] = 13 > > print x > > If you /really/ need a sorted mapping datatype, google for > "sorteddict" (which

Re: code generation

2011-08-02 Thread Dan Stromberg
Perhaps: http://code.google.com/p/python-graph/ On Tue, Aug 2, 2011 at 8:03 PM, Rita wrote: > Hello, > > This isn't much of a python question but a general algorithm question. > > I plan to input the following string and I would like to generate something > like this. > > input: a->(b,c)->d > o

Re: parsing in python

2011-08-03 Thread Dan Stromberg
To just split lines into words, you could probably just use a regex. If you need to match things, like quotes or brackets or parens, pyparsing is pretty nice. On Wed, Aug 3, 2011 at 6:26 AM, Jayron Soares wrote: > Hi folks, > > I've created a simple method to grab files texts from directory by w

Re: Hardlink sub-directories and files

2011-08-03 Thread Dan Stromberg
On Wed, Aug 3, 2011 at 2:47 AM, Thomas Jollans wrote: > Is it more portable? I don't actually have cpio installed on this > system. Interesting. Of course, it's probably readily available to you. What *ix are you seeing that doesn't include cpio by default? > Which implementations of cp don

Re: Hardlink sub-directories and files

2011-08-03 Thread Dan Stromberg
On Wed, Aug 3, 2011 at 12:04 AM, Nobody wrote: > On Tue, 02 Aug 2011 02:32:54 -0700, loial wrote: > > > However I do not think it is possible to hard link directories ? > > Modern Unices disallow hard links to directories, as it makes the > directory "tree" not a tree, so anything which performs

Re: Hardlink sub-directories and files

2011-08-03 Thread Dan Stromberg
On Wed, Aug 3, 2011 at 11:49 AM, Thomas Jollans wrote: > > > Interesting. Of course, it's probably readily available to you. What > > *ix are you seeing that doesn't include cpio by default? > > Arch Linux - the base install is quite minimal. I just discovered that I > have a program called bsd

Re: Hardlink sub-directories and files

2011-08-03 Thread Dan Stromberg
On Wed, Aug 3, 2011 at 2:54 PM, Thomas Jollans wrote: > > On 03/08/11 23:25, Dan Stromberg wrote: > > > Interesting. Of course, it's probably readily available to you. > What > > > *ix are you seeing that doesn't include cpio by default? > &g

Re: Inconsistent SMTP/Gmail connection drop

2011-08-03 Thread Dan Stromberg
Some things to consider: 1) You might see if there's something about the size of the message - is it bigger after collecting data all night? Is google disconnecting after a maximum amount of data is transferred? 2) You might try sending a tiny test message at the beginning, just to yourself, and

Re: PyWhich

2011-08-04 Thread Dan Stromberg
On Thu, Aug 4, 2011 at 10:22 AM, Chris Rebert wrote: > > > #!/usr/bin/python > > > > import sys > > if __name__ == '__main__': > >if len(sys.argv) > 1: > >try: > >m = __import__(sys.argv[1]) > >sys.stdout.write(m.__file__ + '\n') > >sys.stdout.flush

Re: problem with bcd and a number

2011-08-04 Thread Dan Stromberg
It sounds like you have what you need, but here's an amusing way of dealing with a BCD byte: >>> print int(hex(0x72).replace('0x', '')) 72 On Thu, Aug 4, 2011 at 5:15 PM, shawn bright wrote: > Thanks for your help on this, gents. Got it working now. > shawn > > On Thu, Aug 4, 2011 at 2:28 PM, D

Re: Sockets: Receiving C Struct

2011-08-05 Thread Dan Stromberg
First, s.recv(4) is not guaranteed to always return 4 bytes. It could return 0, 1, 2, 3, or 4, wtih 4 being the most likely. To deal with this, I tend to use http://stromberg.dnsalias.org/~dstromberg/bufsock.html - but I suspect that Twisted has a way of dealing with it too. Then, to put your da

Re: Complex sort on big files

2011-08-05 Thread Dan Stromberg
Yup. Timsort is described as "supernatural", and I'm inclined to believe it. On Fri, Aug 5, 2011 at 7:54 PM, Roy Smith wrote: > Wow. > > Python took just about half the time. Certainly knocked my socks off. > Hard to believe, actually. > -- > http://mail.python.org/mailman/listinfo/python-li

Re: Inconsistent SMTP/Gmail connection drop

2011-08-05 Thread Dan Stromberg
Well, a sniffer is one of many, and one worth mentioning. Though I'd recommend wireshark over tcpdump, pretty much any day. http://stromberg.dnsalias.org/~dstromberg/Problem-solving-on-unix-linux-systems.html On Fri, Aug 5, 2011 at 6:29 PM, BJ Swope wrote: > The best tool to debug this is tcpd

Re: Segmentation Fault on exit

2011-08-06 Thread Dan Stromberg
I have little reason to doubt that it's related to referencing counting, but: http://stromberg.dnsalias.org/~dstromberg/checking-early.html On Sat, Aug 6, 2011 at 3:35 AM, Vipul Raheja wrote: > Hi, > > I have wrapped a library from C++ to Python using SWIG. But when I > import it in Python, I a

Re: help

2011-08-06 Thread Dan Stromberg
I'll be a lot easier for you to get help, if you take a shot at it yourself first, then post a link to what you have here, along with any error messages you may be getting. On Sat, Aug 6, 2011 at 1:38 PM, aahan noor wrote: > > Hi all: > i am new to python. i am working with lm-sensors to monito

Re: Object Diffs

2011-08-08 Thread Dan Stromberg
You probably need a recursive algorithm to be fully general, and yes, looking at pickle might be a good place to start. Note that pickle can't pickle everything, but it can handle most things. Also check out NX - not the CPU feature, but the (re)transmission compressing software (there are two di

Re: Need help with Python to C code compiler

2011-08-08 Thread Dan Stromberg
Shedskin is one option - if it doesn't have the modules you need, you could try finding pure python versions of them and translating them too, along with your own code. Cython is probably the one I hear the most about. On Mon, Aug 8, 2011 at 10:37 PM, Vijay Anantha Murthy < vijay.mur...@gmail.com

Re: allow line break at operators

2011-08-10 Thread Dan Sommers
hod(object3, thing) + longfunctionname(object2) + otherfunction(value1, value2, value3)) -- Dan -- http://mail.python.org/mailman/listinfo/python-list

Re: problem installing psyco on windows (Unable to find vcvarsall.bat)

2011-08-10 Thread Dan Stromberg
FWIW, a few months ago I was working on a database application on Windows, and I benchmarked the psyco-enhanced version consistently running slower than the non-psyco version. The same code on Linux was faster with psyco though. If you need performance, and you aren't constrained by module availa

Re: Processing a large string

2011-08-12 Thread Dan Stromberg
This is the sort of thing I wrote bufsock for. Don't let the name fool you - although I originally wrote it for sockets, it's since been extended to work with files and file handles. http://stromberg.dnsalias.org/~dstromberg/bufsock.html It was recently modified to work on 2.x and 3.x. On Thu,

Re: Java is killing me! (AKA: Java for Pythonheads?)

2011-08-12 Thread Dan Stromberg
Check varargs (as another poster mentioned), and consider doing your unit tests in Jython. Some shops that don't want Python for production code are fine with Python for unit tests. However, if the reason for preferring java is type checking, you could perhaps get somewhere by suggesting pylint.

Re: Why no warnings when re-assigning builtin names?

2011-08-15 Thread Dan Stromberg
On Mon, Aug 15, 2011 at 2:52 PM, Gerrat Rickert wrote: > With surprising regularity, I see program postings (eg. on StackOverflow) > from inexperienced Python users accidentally re-assigning built-in names. > http://pypi.python.org/pypi/pylint checks for this and many other issues. I don't know

Re: testing if a list contains a sublist

2011-08-15 Thread Dan Stromberg
Check out collections.Counter if you have 2.7 or up. If you don't, google for multiset or bag types. On Mon, Aug 15, 2011 at 4:26 PM, Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1

Re: Measure the amount of memory used?

2011-08-18 Thread Dan Stromberg
"A person with one watch knows what time it is. A person with two is never sure." You're probably best off just picking one or more measures that work for your purposes, and going with them. Don't concern yourself overmuch with finding "the" amount. Memory can actually contract on some modern s

Re: List spam

2011-08-18 Thread Dan Stromberg
On Thu, Aug 18, 2011 at 6:39 AM, Jason Staudenmayer < jas...@adventureaquarium.com> wrote: > > > On 18/08/2011 13:58, Jason Staudenmayer wrote: > > > I really like this list as part of my learning tools but the amount > > > of spam that I've been getting from it is CRAZY. Doesn't > > anything get

Re: Replacement for the shelve module?

2011-08-19 Thread Dan Stromberg
On Fri, Aug 19, 2011 at 8:31 AM, Forafo San wrote: > Folks, > What might be a good replacement for the shelve module, but one that > can handle a few gigs of data. I'm doing some calculations on daily > stock prices and the result is a nested list like: > > [[date_1, floating result 1], > [date_

Re: Record seperator

2011-08-27 Thread Dan Stromberg
http://stromberg.dnsalias.org/svn/bufsock/trunk does it. $ cat double-file daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2:2:bin:/bin:/bin/sh sys:x:3:3:sys:/dev:/bin/sh sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/bin/sh man:x:6:12:man:/var/cache/man:/bin/sh root:x:0:0:root:/roo

Re: Checking Signature of Function Parameter

2011-08-29 Thread Dan Stromberg
On Sun, Aug 28, 2011 at 2:20 PM, Travis Parks wrote: > There are some things I want to make sure of. 1) I want to make sure > that source is iterable. 2) More importantly, I want to make sure that > predicate is callable, accepting a thing, returning a bool. > You can check a lot of this stuff ve

Re: idiomatic analogue of Perl's: while (<>) { ... }

2011-09-01 Thread Dan Sommers
rols the loop in a string (non-empty strings are equivalent to True in this context): while "there is more input": rval = parse(raw_input()) if real is None: print('foo') else: print('bar') (Although now that I've said that, this looks

Re: [OT] Anyone here familiar with installing Open Watcom F77?

2011-09-05 Thread Dan Nagle
win32-1.9.exe. On Usenet, comp.lang.fortran might be the best source of help for this. There's a good chance one of the regulars there can answer you within one or two posts. (I'll not cross-post, you can choose for yourself.) HTH -- Cheers! Dan Nagle -- http://mail.python.org/mailman/listinfo/python-list

Re: Python getting stuck

2011-02-26 Thread Dan Stromberg
On Sat, Feb 26, 2011 at 4:03 PM, Corey Richardson wrote: > On 02/26/2011 06:55 PM, Shanush Premathasarathan wrote: > > Hi All, > > > > When I use cut, copy, paste, and any keyboard shortcuts, Python freezes > and I am unable to use Python. Please Help as quick as possible!!! > > What OS? Are you

Re: OT: Code Examples

2011-03-01 Thread Dan Stromberg
On Tue, Mar 1, 2011 at 8:51 AM, Erik de Castro Lopo wrote: > Definitely not. As I said I used Python for a number of years > and ditched it in favour of Ocaml and Haskell. > These are all 3 intriguing languages. I wish I had time to learn OCaML and Haskell, and I wish one or both of them were nea

Re: 2to3 and maketrans

2011-03-03 Thread Dan Stromberg
On Wed, Mar 2, 2011 at 10:58 PM, Gregory Ewing wrote: > What is the recommended way to write code for 2.7 using > maketrans() on text strings in such a way that it will > convert correctly using 2to3? > > There seems to be two versions of maketrans in 3.x, one > for text and one for bytes. Code th

Re: 2to3 and maketrans

2011-03-03 Thread Dan Stromberg
On Thu, Mar 3, 2011 at 3:46 PM, Martin v. Loewis wrote: > That depends on how you chose to represent text in 2.7. > The recommended way for that (also with 3.x in mind) > is that you should use Unicode strings to represent text. > For application programming, I'm sure Unicode is usually preferab

Re: auto increment

2011-03-03 Thread Dan Stromberg
On Thu, Mar 3, 2011 at 8:48 PM, Chris Rebert wrote: > On Thu, Mar 3, 2011 at 8:41 PM, monkeys paw wrote: > > Does python have an analogy to c/perl incrementer? > > > > e.g. > > > > i = 0 > > i++ > > i += 1 > > If you're doing this for a list index, use enumerate() instead. > There's been discus

Re: auto increment

2011-03-03 Thread Dan Stromberg
On Thu, Mar 3, 2011 at 9:07 PM, Chris Rebert wrote: > On Thu, Mar 3, 2011 at 9:05 PM, Dan Stromberg wrote: > > On Thu, Mar 3, 2011 at 8:48 PM, Chris Rebert wrote: > >> On Thu, Mar 3, 2011 at 8:41 PM, monkeys paw > wrote: > >> > Does python have

Re: What do I need to know in order to write a web application in python?

2011-03-06 Thread Dan Stromberg
On Fri, Mar 4, 2011 at 6:07 PM, Paul Rubin wrote: > ErichCart ErichCart writes: > > By real-time, I mean that I want it to be similar to the way instant > > online chess works. Something like here: instantchess.com, but for > > RISK. > > If you want to do that in a web browser, the main techniqu

Re: I'm happy with Python 2.5

2011-03-06 Thread Dan Stromberg
On Thu, Mar 3, 2011 at 10:43 AM, Ian Kelly wrote: > On Sun, Feb 27, 2011 at 7:15 AM, n00m wrote: > > http://www.spoj.pl/problems/TMUL/ > > > > Python's "print a * b" gets Time Limit Exceeded. > > If speed is the only thing you care about, then you can forget about > fretting over whether 2.5 or

Re: python data types in c++ code

2011-03-06 Thread Dan Stromberg
On Sun, Mar 6, 2011 at 10:07 AM, Arthur Mc Coy <1984docmc...@gmail.com>wrote: > You know, they are still using SVN, they are > very loosely coupled to the past. > Cython's very nice if you don't plan to do more than C/C++ with Python. SWIG might be better if you intend to do more VHLL's than Pyth

Re: Plotting of maps in python

2011-03-07 Thread Dan Friedman
Is this the Jeff Collins that worked at the Skunk works in the early 1990s? -- http://mail.python.org/mailman/listinfo/python-list

Re: Purely historic question: VT200 text graphic programming

2011-03-09 Thread Dan Stromberg
Hm, maybe curses? *ix programmers often know what it is, but it was present on VMS as well. And the python sources come with a curses module. http://h71000.www7.hp.com/doc/732final/5763/5763pro_015.html The main question then becomes, was VMS's curses a termcap curses or a terminfo curses, or so

Re: What do you use with Python for GUI programming and why?

2011-03-10 Thread Dan Stromberg
You're probably best off with Pyjamas. Then you get something that runs on the web and on the desktop, from the same code - similar to GWT, but for Python. The desktop version runs overtop of CPython, the web version is AJAX and is automatically translated from a very 2.x-ish dialect of Python to

Re: Just finished reading of "What’s New In Python 3.0"

2011-03-10 Thread Dan Stromberg
On Thu, Mar 10, 2011 at 6:05 PM, alex23 wrote: > On Mar 11, 11:58 am, n00m wrote: > > http://docs.python.org/py3k/whatsnew/3.0.html > > > > What's the fuss abt it? Imo all is ***OK*** with 3k (in the parts I > > understand). > > I even liked print as a function **more** than print as a stmt > >

Re: Just finished reading of "What’s New In Python 3.0"

2011-03-11 Thread Dan Stromberg
On Thu, Mar 10, 2011 at 11:59 PM, n00m wrote: > Fitzgerald had been an alcoholic since his college days, and became > notorious during the 1920s for his extraordinarily heavy drinking, > leaving him in poor health by the late 1930s. According to Zelda's > biographer, Nancy Milford, Scott claimed

Re: Creating a very simple revision system for photos in python

2011-03-11 Thread Dan Stromberg
On Fri, Mar 11, 2011 at 6:56 AM, Thomas W wrote: > I`m thinking about creating a very simple revision system for photos > in python, something like bazaar, mercurial or git, but for photos. > The problem is that handling large binary files compared to plain text > files are quite different. Has a

Re: Two random lists from one list

2011-03-11 Thread Dan Stromberg
Catenate the lists into a new list. Then randomize the order of the new list by iterating over each element in turn, swapping it with a random element elsewhere in the same list (optionally including swapping it with itself - that's easier and still gives good randomization). This gives linear ti

Re: What do you use with Python for GUI programming and why?

2011-03-11 Thread Dan Stromberg
On Fri, Mar 11, 2011 at 12:54 PM, Fred Pacquier wrote: > Robert said : > > > Is there a push to one toolkit or the other? > > If you are just now getting started, I would honestly suggest you save a > whole lot of time and dive straight into PyQt. I've tried most 'em over the > years (including s

Re: Calling C++ Modules in Python

2011-03-11 Thread Dan Stromberg
On Fri, Mar 11, 2011 at 1:15 PM, Patrick wrote: > Hi, > > I saw in the Beginner document that "•Is easily extended by adding new > modules implemented in a compiled language such as C or C++. ". > > While to my investigation, it seems not that easy or did I miss > something? > > boost python (C++

Re: Re: Calling C++ Modules in Python

2011-03-11 Thread Dan Stromberg
I've not tried Boost, but I don't think SWIG or Cython require modified libraries. You just compile your wrapper, and then import it. On Fri, Mar 11, 2011 at 2:16 PM, wrote: > Dan, > > Thanks for the info. Really I was hoping for a "non-intrusive" way to >

Re: How should I handle socket receiving?

2011-03-11 Thread Dan Stromberg
On Fri, Mar 11, 2011 at 3:30 PM, Hans wrote: > I'm thinking to write a code which to: > 1. establish tons of udp/tcp connections to a server > 2. send packets from each connections > 3. receive packets from each connections and then do something based > on received content and connection statues.

Re: OT: processes, terminals and file descriptors on *nix (was: Re: attach to process by pid?)

2011-03-11 Thread Dan Stromberg
On Fri, Mar 11, 2011 at 3:49 PM, Alexander Kapps wrote: > On 11.03.2011 03:18, Nobody wrote: > >> On Thu, 10 Mar 2011 23:55:51 +0100, Alexander Kapps wrote: >> >> I think he wants to attach to another process's stdin/stdout and > read/write from/to them. > I don't know if this is possibl

Re: Memory Usage of Strings

2011-03-16 Thread Dan Stromberg
On Wed, Mar 16, 2011 at 8:38 AM, Amit Dev wrote: > I'm observing a strange memory usage pattern with strings. Consider > the following session. Idea is to create a list which holds some > strings so that cumulative characters in the list is 100MB. > > >>> l = [] > >>> for i in xrange(10): > .

Re: organizing many python scripts, in a large corporate environment.

2011-03-16 Thread Dan Stromberg
If you just want to be unhappy about the current situation, I hereby formally bestow upon you permission to be so. :) The problem seems to be that you want to hook into the python process, without hooking into the python process. Were this possible, it seems we might have a serious security issu

Re: Fitting polynomial curve

2011-03-17 Thread Dan Stromberg
On Thu, Mar 17, 2011 at 5:44 PM, Astan Chee wrote: > > On Thu, Mar 17, 2011 at 5:09 PM, Terry Reedy wrote: > >> Look at scipy. >> > > Thanks for the info. I realized I made some mistakes. Anyway, what I'm > trying to do is in maya (python), fit selected vertices on a curve. Here is > what I have

Re: Reading/Writing files

2011-03-18 Thread Dan Stromberg
For open() or os.open(), it should look in your Current Working Directory (CWD). Your python's CWD defaults to what the CWD was when python was started, and it is changed with os.chdir(). Absolute paths will of course be relative to / on most OS's (or C:/ if you're on C:, D:/ if you're on D:, etc

Re: Reading/Writing files

2011-03-18 Thread Dan Stromberg
Are you on windows? You probably should use / as your directory separator in Python, not \. In Python, and most other programming languages, \ starts an escape sequence, so to introduce a literal \, you either need to prefix your string with r (r"\foo\bar") or double your backslashes ("\\foo\\bar

Re: Bounds checking

2011-03-18 Thread Dan Stromberg
Actually, I'd probably create a class with 3 arguments - an initial value, a lower bound, and an upper bound, give it a _check method, and call _check from the various operator methods. The class would otherwise impersonate an int. In code that isn't performance-critical, it's better to check for

Re: Reading/Writing files

2011-03-18 Thread Dan Stromberg
On Fri, Mar 18, 2011 at 4:00 PM, Ethan Furman wrote: > Dan Stromberg wrote: > >> >> Are you on windows? >> >> You probably should use / as your directory separator in Python, not \. >> In Python, and most other programming languages, \ starts an escape &g

Re: Reading/Writing files

2011-03-19 Thread Dan Stromberg
On Sat, Mar 19, 2011 at 12:55 AM, Nobody wrote: > On Fri, 18 Mar 2011 16:00:55 -0700, Ethan Furman wrote: > > Dan Stromberg wrote: > > > / works fine on windows, and doesn't require escaping ("/foo/bar"). > > "/" works fine in most

Re: os.walk/list

2011-03-19 Thread Dan Stromberg
You're not really supposed to call into the md5 module directly anymore; you might use hashlib instead. But actually, using a cryptographic hash doesn't really help comparing just one pair of files; it's more certain to do a block by block comparison, and the I/O time is roughly the same - actuall

Re: os.utime

2011-03-20 Thread Dan Stromberg
1) If you want to set the ctime to the current time, you can os.rename() the file to some temporary name, and then quickly os.rename() it back. 2) You can sort of set a file to have an arbitrary ctime, by setting the system's clock to what you need, and then doing the rename thing above - then res

Re: os.utime

2011-03-20 Thread Dan Stromberg
On Sun, Mar 20, 2011 at 7:12 PM, Christian Heimes wrote: > Am 21.03.2011 01:40, schrieb Dan Stromberg: > > 1) If you want to set the ctime to the current time, you can os.rename() > the > > file to some temporary name, and then quickly os.rename() it back. > > > >

Re: os.utime

2011-03-22 Thread Dan Stromberg
On Mon, Mar 21, 2011 at 2:43 AM, Christian Heimes wrote: > I'm sorry if I offended you in any way. I had to clarify the meaning of > st_ctime many times in the past because people confused it for the > creation ts of the file. > Apologies if I got too defensive. I agree that it was worth pointin

Re: os.stat bug?

2011-03-22 Thread Dan Stromberg
On Mon, Mar 21, 2011 at 1:32 AM, Laszlo Nagy wrote: > > Hi All, > > I have a Python program that goes up to 100% CPU. Just like this (top): > > PID USERNAME THR PRI NICE SIZERES STATE C TIME WCPU > COMMAND > 80212 user1 2 440 70520K 16212K select 1 0:30 100.0

Re: Special logging module needed

2011-03-23 Thread Dan Stromberg
On Wed, Mar 23, 2011 at 7:37 AM, Laszlo Nagy wrote: > I was also thinking about storing data in a gdbm database. One file for > each month storing at most 100 log messages for every key value. Then one > file for each day in the current month, storing one message for each key > value. Incrementa

Re: Instant File I/O

2011-03-23 Thread Dan Stromberg
I'm not familiar with linecache.clearcache(), but did you flush the data to the filesystem with file_.flush() ? On Wed, Mar 23, 2011 at 9:53 PM, jam1991 wrote: > I'm trying to build a feature on to a text-based game that I've been > working on that would allow users to view their stats. Informat

Re: Reading/Writing files

2011-03-25 Thread Dan Stromberg
On Fri, Mar 25, 2011 at 6:42 AM, Westley Martínez wrote: > > > > I argue that the first is quite a bit more readable than the second: > > > 'c:/temp/choose_python.pdf' > > > os.path.join([ 'c:', 'temp', 'choose_python.pdf' ]) > > > > I agree with your argument, but think that > > r'c:\tem

Re: Guido rethinking removal of cmp from sort method

2011-03-25 Thread Dan Stromberg
On Sun, Mar 13, 2011 at 5:59 AM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > The removal of cmp from the sort method of lists is probably the most > disliked change in Python 3. On the python-dev mailing list at the > moment, Guido is considering whether or not it was a mistak

Re: Dump interpreter history?

2011-03-25 Thread Dan Mahoney
Yeah, sorry about that. The square brackets were supposed to indicate that filename is an optional argument. If not supplied, defaults to .history. Dan Mahoney catd...@gmail.com Sent from my Android phone On Mar 25, 2011 6:57 PM, "Tim Chase" wrote: On 03/25/2011 04:40 PM, Daniel Mah

Re: Writing to a file

2011-03-25 Thread Dan Stromberg
with closes the file for you, when the indented block is exited. ~ isn't cross-platform at all, in fact it's not precisely python, though os.path.expanduser understands it. AFAIK, the jury's still out on whether the /'s in pathnames as directory separators are portable. I know they work on *ix a

Re: best python games?

2011-03-25 Thread Dan Stromberg
On Fri, Mar 25, 2011 at 7:39 PM, sogeking99 wrote: > hey guys, what are some of the best games made in python? free games > really. like pygames stuff. i want to see what python is capable of. > > cant see any good one on pygames site really, though they have nothing > like sort by rating or most

Re: Guido rethinking removal of cmp from sort method

2011-03-26 Thread Dan Stromberg
(Trying again to get through to python-list) On Sat, Mar 26, 2011 at 2:10 AM, Steven D'Aprano wrote: > > Dan Stromberg wrote: > > There's also the issue of a lazy comparison function, that I don't seem to >> have gotten a response to - if you have a Very

Re: Guido rethinking removal of cmp from sort method

2011-03-28 Thread Dan Stromberg
On Mon, Mar 28, 2011 at 6:58 PM, Paul Rubin wrote: > DSU is a clever and useful design pattern, but comparison > sorting is what all the sorting textbooks are written about. > Actually, even though I wrote one program that could almost benefit from cmp sorting that might have trouble with key so

Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread Dan Stromberg
On Tue, Mar 29, 2011 at 1:46 AM, Antoon Pardon wrote: > The double sort is useless if the actual sorting is done in a different > module/function/method than the module/function/method where the order > is implemented. It is even possible you didn't write the module > where the sorting actually o

Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread Dan Stromberg
On Tue, Mar 29, 2011 at 12:48 PM, Ian Kelly wrote: > On Tue, Mar 29, 2011 at 1:08 PM, Chris Angelico wrote: > > On Wed, Mar 30, 2011 at 5:57 AM, MRAB > wrote: > >> You would have to do more than that. > >> > >> For example, "" < "A", but if you "negate" both strings you get "" < > >> "\xBE", no

Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread Dan Stromberg
On Thu, Mar 31, 2011 at 9:18 AM, Chris Angelico wrote: > On Fri, Apr 1, 2011 at 3:12 AM, eryksun () wrote: > > There appears to be a formatting error here. > > So remind me again why Python likes whitespace to be significant? > > > http://stromberg.dnsalias.org/~strombrg/significant-whitespace

Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread Dan Stromberg
On Thu, Mar 31, 2011 at 1:35 PM, Chris Angelico wrote: > On Fri, Apr 1, 2011 at 4:54 AM, Dan Stromberg wrote: > > > > http://stromberg.dnsalias.org/~strombrg/significant-whitespace.html > > > > I was trolling, I know the reasons behind it. Anyway, most people

Re: a basic bytecode to machine code compiler

2011-03-31 Thread Dan Stromberg
On Thu, Mar 31, 2011 at 5:52 PM, Terry Reedy wrote: > On 3/31/2011 6:33 PM, Rouslan Korneychuk wrote: > >> I was looking at the list of bytecode instructions that Python uses and >> I noticed how much it looked like assembly. So I figured it can't be to >> hard to convert this to actual machine c

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