Re: python backup script

2013-05-06 Thread Peter Otten
Chris Angelico wrote: > It's also worth noting that the ~/ notation is a shell feature. You > may or may not be able to use it in config.read(). The latter. Combined with """ read(self, filenames) method of ConfigParser.ConfigParser instance Read and parse a filename or a list of filenames.

Re: formatted output

2013-05-07 Thread Peter Otten
Roy Smith wrote: > In article , > Sudheer Joseph wrote: > >> Dear members, >> I need to print few arrays in a tabular form for example >> below array IL has 25 elements, is there an easy way to print >> this as 5x5 comma separated table? in python >> >> IL=[

Re: Diacretical incensitive search

2013-05-17 Thread Peter Otten
Olive wrote: > One feature that seems to be missing in the re module (or any tools that I > know for searching text) is "diacretical incensitive search". I would like > to have a match for something like this: > > re.match("franc", "français") > > in about the same whay we can have a case incens

Re: Please help with Threading

2013-05-18 Thread Peter Otten
Jurgens de Bruin wrote: > This is my first script where I want to use the python threading module. I > have a large dataset which is a list of dict this can be as much as 200 > dictionaries in the list. The final goal is a histogram for each dict 16 > histograms on a page ( 4x4 ) - this already w

Re: Please help with Threading

2013-05-18 Thread Peter Otten
Jurgens de Bruin wrote: > I will post code - the entire scripts is 1000 lines of code - can I post > the threading functions only? Try to condense it to the relevant parts, but make sure that it can be run by us. As a general note, when you add new stuff to an existing longish script it is alw

Re: TypeError: unbound method add() must be called with BinaryTree instance as first argument (got nothing instead)

2013-05-18 Thread Peter Otten
Dan Stromberg wrote: > I'm getting the error in the subject, from the following code: > def add(self, key): > """ > Adds a node containing I{key} to the subtree > rooted at I{self}, returning the added node. > """ > node = self.find(key) > if not

Re: TypeError: unbound method add() must be called with BinaryTree instance as first argument (got nothing instead)

2013-05-18 Thread Peter Otten
Dan Stromberg wrote: > python 2.x, python 3.x and pypy all give this same error, though jython > errors out at a different point in the same method. By the way, 3.x doesn't have unbound methods, so that should work. -- http://mail.python.org/mailman/listinfo/python-list

Re: mutable ints: I think I have painted myself into a corner

2013-05-19 Thread Peter Otten
Cameron Simpson wrote: > TL;DR: I think I want to modify an int value "in place". > > Yesterday I was thinking about various "flag set" objects I have > floating around which are essentially bare "object"s whose attributes > I access, for example: > > flags = object() > flags.this = True >

Re: Python Windows release and encoding

2013-05-22 Thread Peter Otten
Absalom K. wrote: > Hi, I am working on Linux; a friend of mine sends to me python files from > his Windows release. He uses the editor coming with the release; he runs > his code from the editor by using a menu (or some F5 key I think). > > He doesn't declare any encoding in his source file; whe

Re: newbie question about subprocess.Popen() arguments

2013-05-23 Thread Peter Otten
Alex Naumov wrote: > I'm trying to call new process with some parameters. The problem is that > the last parameter is a "string" that has a lot of spaces and different > symbols like slash and so on. I can save it in file and use name of this > file as parameter, but my question is: how to make it

Re: Scope of a class..help???

2013-05-23 Thread Peter Otten
lokeshkopp...@gmail.com wrote: > i had written the following code i am unable to create the instance of the > class "Node" in the method "number_to_LinkedList" can any one help me how > to do ?? and what is the error?? > > > class Node: > def __init__(self, value=None): > self.valu

Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Peter Otten
Νίκος Γκρ33κ wrote: > Hello this is the following snippet that is causing me the error i mention > in the Subject: > print( " color=tomato size=5> %s " ) % (url, url) Hint (Python 3): >>> print("a=%s, b=%s") % (1, 2) a=%s, b=%s Traceback (most recent call last): File "", line 1, in TypeError

Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Peter Otten
Νίκος Γκρ33κ wrote: > Thank you very much Peter, so as it seems in Python 3.3.1 all > substitutuons must be nested in print(). Yes; in other words: In Python 3 print() is a function. -- http://mail.python.org/mailman/listinfo/python-list

Re: Error when trying to sort and presnt a dictionary in python 3.3.1

2013-05-26 Thread Peter Otten
Νίκος Γκρ33κ wrote: > python3 pelatologio.py gives me error in this line: > > Traceback (most recent call last): > File "pelatologio.py", line 283, in > ''' % (months[key], key) ) > KeyError: 1 > > The code is: > > #populating months into a dropdown menu > years = ( 2010, 2011,

Re: IndentationError: expected an indented block but it's there

2013-05-28 Thread Peter Otten
JackM wrote: > Having a problem getting a py script to execute. Got this error: > > File "/scripts/blockIPv4.py", line 19 > ip = line.split(';')[0] > ^ > IndentationError: expected an indented block > > > I'm perplexed because the code that the error refers to *is* indented: > > >

Re: IndentationError: expected an indented block but it's there

2013-05-28 Thread Peter Otten
Chris Angelico wrote: > On Wed, May 29, 2013 at 2:19 AM, Peter Otten <__pete...@web.de> wrote: >> Solution: configure your editor to use four spaces for indentation. > > ITYM eight spaces. I meant: one hit of the Tab key should add spaces up to the next multiple of four.

Re: Piping processes works with 'shell = True' but not otherwise.

2013-05-31 Thread Peter Otten
Luca Cerone wrote: >> >> That's because stdin/stdout/stderr take file descriptors or file >> >> objects, not path strings. >> > > Thanks Chris, how do I set the file descriptor to /dev/null then? For example: with open(os.devnull, "wb") as stderr: p = subprocess.Popen(..., stderr=stderr)

Re: Surprising difference between StringIO.StringIO and io.StringIO

2013-05-31 Thread Peter Otten
Serhiy Storchaka wrote: > 30.05.13 23:46, Skip Montanaro написав(ла): >> Am I missing something about how io.StringIO works? I thought it was >> a more-or-less drop-in replacement for StringIO.StringIO. > > io.StringIO was backported from Python 3. It is a text (unicode) stream. > cStringIO.Stri

Re: Beginner question

2013-06-04 Thread Peter Otten
Chris Angelico wrote: > On Tue, Jun 4, 2013 at 5:57 PM, John Ladasky > wrote: >> On Tuesday, June 4, 2013 12:45:38 AM UTC-7, Anssi Saari wrote: >> >>> BTW, did I get the logic correctly, the end result is random? >> >> You're right! I'm guessing that's not what the OP wants? > > I'm guessing th

Re: lstrip problem - beginner question

2013-06-04 Thread Peter Otten
mstagliamonte wrote: > Hi everyone, > > I am a beginner in python and trying to find my way through... :) > > I am writing a script to get numbers from the headers of a text file. > > If the header is something like: > h01 = ('>scaffold_1') > I just use: > h01.lstrip('>scaffold_') > and this re

Re: Issue values dictionary

2013-06-05 Thread Peter Otten
alex23 wrote: > def get_transcript_and_size(line): > columns = line.strip().split() > return columns[0].strip(), int(columns[1].strip()) You can remove all strip() methods here as split() already strips off any whitespace from the columns. Not really important, but the nitp

Re: Thread-safe way to prevent decorator from being nested

2013-06-07 Thread Peter Otten
Michael wrote: > I'm writing a decorator that I never want to be nested. Following from the > answer on my StackOverflow question > (http://stackoverflow.com/a/16905779/106244), I've adapted it to the > following. > > Can anyone spot any issues with this? It'll be run in a multi-threaded > enviro

Re: Problems with serial port interface

2013-06-07 Thread Peter Otten
lionelgreenstr...@gmail.com wrote: > Sorry for my quote, > but do you have any suggestion? >> After 30seconds (more or less) the program crashes: seems a buffer >> problem, but i'm not really sure. >> >> What's wrong? I don't use qt or pyserial myself, but your problem description is too vague

Re: Trying to work with data from a query using Python.

2013-06-07 Thread Peter Otten
ethereal_r...@hotmail.com wrote: > Hello, I'm working with PostgreSQL and Python to obtain 2 columns froma > database and need to print it in a specific format. > > Here is my current code. > > > > #!/usr/bin/python > # -*- coding: utf-8 -*- > > import psycopg2 > import sys > > con = None >

Re: Idiomatic Python for incrementing pairs

2013-06-07 Thread Peter Otten
Tim Chase wrote: > On 2013-06-07 23:46, Jason Swails wrote: >> On Fri, Jun 7, 2013 at 10:32 PM, Tim Chase >> > def calculate(params): >> > a = b = 0 >> > if some_calculation(params): >> > a += 1 >> > if other_calculation(params): >> > b += 1 >> > return (a, b) >> > >>

Re: I used defaultdic to store some variables but the output is blank

2013-06-09 Thread Peter Otten
claire morandin wrote: > I have the following script which does not return anything, no apparent > mistake but my output file is empty.I am just trying to extract some > decimal number from a file according to their names which are in another > file. from collections import defaultdict import nump

Re: I used defaultdic to store some variables but the output is blank

2013-06-09 Thread Peter Otten
claire morandin wrote: > Thanks Peter, true I did not realize that ercc_contigs is empty, but I am > not sure how to "populate" the dictionary if I only have one column for > the value but no key You could use a "dummy value" ercc_contigs = {} for line in open('Faq_ERCC_contigs_name.txt'): g

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Peter Otten
Rui Maciel wrote: > Let: > - class Point be a data type which is used to define points in space > - class Line be a data type which possesses an aggregate relationship with > objects of type Point > - class Model be a container class which stores collections of Point and > Line objects > > > Ess

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Peter Otten
Rui Maciel wrote: > Peter Otten wrote: > >> Don't add >> >>>position = [] >> >> to your code. That's not a declaration, but a class attribute and in the >> long run it will cause nothing but trouble. > > Why's that? Especial

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Peter Otten
Rui Maciel wrote: > How do you guarantee that any object of a class has a specific set of > attributes? You don't. Such a guarantee is like the third wheel on a bike -- it doesn't improve the overall experience. PS: I'd rather not mention the memory-saving technique that is sometimes abused,

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Peter Otten
Rui Maciel wrote: > Peter Otten wrote: > >> Rui Maciel wrote: >> >>> How do you guarantee that any object of a class has a specific set of >>> attributes? >> >> You don't. > > > What's your point regarding attribute assignme

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Peter Otten
Rui Maciel wrote: > Peter Otten wrote: > >> I don't understand the question. My original point was that you should >> omit class attributes that don't fulfill a technical purpose. >> > > You've said the following: > > >> class Point

Re: Split a list into two parts based on a filter?

2013-06-10 Thread Peter Otten
Chris Angelico wrote: > On Tue, Jun 11, 2013 at 6:34 AM, Roy Smith wrote: >> new_songs = [s for s in songs if s.is_new()] >> old_songs = [s for s in songs if not s.is_new()] > > Hmm. Would this serve? > > old_songs = songs[:] > new_songs = [songs.remove(s) or s for s in songs if s.is_new()] >

Re: Split a list into two parts based on a filter?

2013-06-10 Thread Peter Otten
Fábio Santos wrote: > On 10 Jun 2013 23:54, "Roel Schroeven" wrote: >> >> You could do something like: >> >> new_songs, old_songs = [], [] >> [(new_songs if s.is_new() else old_songs).append(s) for s in songs] >> >> But I'm not sure that that's any better than the long version. > > This is so be

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-11 Thread Peter Otten
Terry Jan Reedy wrote: > Many long-time posters have advised "Don't rebind built-in names*. I'm in that camp, but I think this old post by Guido van Rossum is worth reading to put the matter into perspective: """ > That was probably a checkin I made. I would have left it alone except the > cod

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-11 Thread Peter Otten
rusi wrote: > On Jun 11, 12:09 pm, Peter Otten <__pete...@web.de> wrote: >> Terry Jan Reedy wrote: >> > Many long-time posters have advised "Don't rebind built-in names*. >> >> I'm in that camp, but I think this old post by Guido van Rossum is

Re: Split a list into two parts based on a filter?

2013-06-11 Thread Peter Otten
Chris Angelico wrote: > On Wed, Jun 12, 2013 at 1:28 AM, Serhiy Storchaka > wrote: >> 11.06.13 01:50, Chris Angelico написав(ла): >> >>> On Tue, Jun 11, 2013 at 6:34 AM, Roy Smith wrote: new_songs = [s for s in songs if s.is_new()] old_songs = [s for s in songs if not s.is_new()]

Re: Split a list into two parts based on a filter?

2013-06-11 Thread Peter Otten
Joshua Landau wrote: > On 11 June 2013 01:11, Peter Otten <__pete...@web.de> wrote: >> def partition(items, predicate=bool): >> a, b = itertools.tee((predicate(item), item) for item in items) >> return ((item for pred, item in a if not pred), >>

Re: ValueError: I/O operation on closed file. with python3

2013-06-12 Thread Peter Otten
Adam Mercer wrote: > Hi > > I'm trying to update one of my scripts so that it runs under python2 > and python3, but I'm running into an issue that the following example > illustrates: > > $ cat test.py > try: > # python-2.x > from urllib2 import urlopen > from ConfigParser import ConfigPar

Re: Modify code with AST

2013-06-12 Thread Peter Otten
Ronny Mandal wrote: > Hello, > > I am trying to write a script which will parse a code segment (with > ast.parse()), locate the correct function/method node (by name) in the > resulting tree and replace this function (node) with another function > (node), e.g.: > > MyMod1.py: > > class FooBar()

Re: How to pass instance into decorator function

2013-06-13 Thread Peter Otten
Jayakrishnan Damodaran wrote: > I have a class which calculates some salary allowances. Instead of a blind > calculation I need to check some conditions before I can return the > calculated amount. Like if all the allowances calculated till now plus the > one in progress must not exceed the total

Re: Memory usage steadily going up while pickling objects

2013-06-14 Thread Peter Otten
Giorgos Tzampanakis wrote: > I have a program that saves lots (about 800k) objects into a shelve > database (I'm using sqlite3dbm for this since all the default python dbm > packages seem to be unreliable and effectively unusable, but this is > another discussion). > > The process takes about 10-

Re: Newbie: The philosophy behind list indexes

2013-06-14 Thread Peter Otten
Chris Rebert wrote: > On Jun 14, 2013 10:26 PM, wrote: >> What is the thinking behind stopping 'one short' when slicing or >> iterating through lists? > I find Dijkstra's explanation rather convincing: > http://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831.html This is the only case whe

Re: Memory usage steadily going up while pickling objects

2013-06-15 Thread Peter Otten
Giorgos Tzampanakis wrote: > So it seems that the pickle module does keep some internal cache or > something like that. I don't think there's a global cache. The Pickler/Unpickler has a per- instance cache (the memo dict) that you can clear with the clear_memo() method, but that doesn't matter

Re: Natural Language Processing with Python .dispersion_plot returns nothing

2013-06-17 Thread Peter Otten
sixtyfourbit wrote: > I'm in the first chapter of Natural Language Processing with Python and am > trying to run the example .dispersion_plot. I am using Python 2.7.4 > (Anaconda) on Mac OSX 10.8. > > When I load all of the necessary modules and try to create the dispersion > plott, I get no retu

Re: Help me with the script? How to find items in csv file A and not in file B and vice versa

2013-06-18 Thread Peter Otten
Alan Newbie wrote: > Hello, > Let's say I want to compare two csv files: file A and file B. They are > both similarly built - the first column has product IDs (one product per > row) and the columns provide some stats about the products such as sales > in # and $. > > I want to compare these file

Re: New line conversion with Popen attached to a pty

2013-06-20 Thread Peter Otten
jfhar...@gmail.com wrote: > Hi, > > Sorry if this appears twice, I sent it to the mailing list earlier and the > mail seems to have been swallowed by the black hole of email vagaries. > > We have a class which executes external processes in a controlled > environment and does "things" specified

Re: Finding all instances of a string in an XML file

2013-06-20 Thread Peter Otten
Jason Friedman wrote: > I have XML which looks like: > > > > > > > > > > > > > > > > > The "Property X" string appears twice times and I want to output the > "path" > that leads to all such appearances. In this case the output would be: > > LEVE

Re: Simple I/O problem can't get solved

2013-06-21 Thread Peter Otten
nickgan@windowslive.com wrote: > I have recently started to solve my first Python problems but I came > across to this: > Write a version of a palindrome recogniser that accepts a file name from > the user, reads each line, and prints the line to the screen if it is a > palindrome.(by http://w

Re: how can I check if group member exist ?

2013-06-21 Thread Peter Otten
Hans wrote: > Hi, > > I'm doing a regular expression matching, let's say > "a=re.search(re_str,match_str)", if matching, I don't know how many > str/item will be extracted from re_str, maybe a.group(1), a.group(2) exist > but a.group(3) does not. > > Can I somehow check it? something like: > if

Re: n00b question on spacing

2013-06-21 Thread Peter Otten
Yves S. Garret wrote: > Hi, I have a question about breaking up really long lines of code in > Python. > > I have the following line of code: > log.msg("Item wrote to MongoDB database %s/%s" %(settings['MONGODB_DB'], > settings['MONGODB_COLLECTION']), level=log.DEBUG, spider=spider) > > Given th

Re: Simple I/O problem can't get solved

2013-06-22 Thread Peter Otten
Chris Angelico wrote: > On Fri, Jun 21, 2013 at 7:15 PM, Peter Otten <__pete...@web.de> wrote: >> Combining these modifications: >> >> for line in f: >> word = line.strip() >> if is_palindrome.is_palindrome(word): >> print word >

Re: How can i fix this?

2013-06-22 Thread Peter Otten
Борислав Бориславов wrote: > while 1: > name=raw_input("What is your name? ") > if name == "bobi": print "Hello Master!" and break > else: print "error" > I want if my conditions are met to do a couple of things and i cant do > that > while 1: > name=raw_input("What is your name?

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread Peter Otten
pablobarhamal...@gmail.com wrote: > Hi there! I'm quite new to programming, even newer in python (this is > actually the first thing I try on it), and every other topic I've seen on > forums about my problem doesn't seem to help. > > So, the following lines are intended to draw a white square (wh

Re: Question about pickle

2013-06-25 Thread Peter Otten
Phu Sam wrote: > I have a method that opens a file, lock it, pickle.load the file into a > dictionary. > I then modify the status of a record, then pickle.dump the dictionary back > to the file. > > The problem is that the pickle.dump never works. The file never gets > updated. > > def updateSta

Re: Inconsistency on getting arguments

2013-06-25 Thread Peter Otten
Marco Perniciaro wrote: > Hi, > I've been working with Python for a long time. > Yet, I came across an issue which I cannot explain. > > Recently I have a new PC (Windows 7). > Previously I could call a Python script with or without the "python" word > at the beginning. Now the behavior is differ

Re: class factory question

2013-06-26 Thread Peter Otten
Tim wrote: > I am extending a parser and need to create many classes that are all > subclassed from the same object (defined in an external library). When my > module is loaded I need all the classes to be created with a particular > name but the behavior is all the same. Currently I have a bunch

Re: class factory question

2013-06-26 Thread Peter Otten
Tim wrote: > I am not completely understanding the type function I guess. Here is an > example from the interpreter: > > In [1]: class MyClass(object): >...: pass >...: > In [2]: type('Vspace', (MyClass,), {}) > Out[2]: __main__.Vspace > In [3]: x = Vspace() > ---

Re: class factory question

2013-06-26 Thread Peter Otten
Joshua Landau wrote: > I would say if a dict isn't good, there are still some cases where you > might not want to use globals. > > I _might_ do: > # Make a module > module_for_little_classes = ModuleType("module_for_little_classes", > "All the things") > module_for_little_classes.__dict__.update

Re: warnings filters for varying message

2013-06-28 Thread Peter Otten
John Reid wrote: > Looking at the docs for warnings.simplefilter > (http://docs.python.org/2/library/warnings.html) I think the following > script should only produce one warning at each line as any message is > matched by the simple filter > > import warnings > warnings.simplefilter('default') >

Re: ? get negative from prod(x) when x is positive integers

2013-06-28 Thread Peter Otten
Vincent Davis wrote: > I have a list of a list of integers. The lists are long so i cant really > show an actual example of on of the lists, but I know that they contain > only the integers 1,2,3,4. so for example. > s2 = [[1,2,2,3,2,1,4,4],[2,4,3,2,3,1]] > > I am calculating the product, sum, ma

Re: Closures in leu of pointers?

2013-06-29 Thread Peter Otten
cts.private.ya...@gmail.com wrote: > I'd like to use closures to set allow a subroutine to set variables in its > caller, in leu of pointers. "leu"? Must be a Fench word ;) > But I can't get it to work. I have the > following test pgm, but I can't understand its behaviour: > > It uses a functi

Re: Closures in leu of pointers?

2013-06-29 Thread Peter Otten
cts.private.ya...@gmail.com wrote: > As for python 3 ... "nonlocal"? I see I'm not alone in picking obnoxious > names ... tous chez... > Alas, one reason it's a weak workaround is that it doesn't work - at > least, not how I wish it would: > $ cat ptrs > > x = 34 > > def p1 (a1): > > a1

Re: python3 import idlelib.PyShell fails

2013-06-30 Thread Peter Otten
Helmut Jarausch wrote: > Hi, > > I have a strange error. When I try import idlelib.PyShell from Python3.3 > it fails with > > Python 3.3.2+ (3.3:68ff68f9a0d5+, Jun 30 2013, 12:59:15) > [GCC 4.7.3] on linux > Type "help", "copyright", "credits" or "license" for more information. import idlel

Re: How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-07-02 Thread Peter Otten
Ven wrote: > I use: Python 2.6 and sqlalchemy 0.6.1 > > This is what I am trying to do: > > from sqlalchemy.types import ( > Integer, > String, > Boolean > ) > from sqlalchemy.ext.declarative import declarative_base > > Base = declarative_base() > > class SampleMeta(type): > def __

Re: Decorator help

2013-07-03 Thread Peter Otten
Joshua Landau wrote: > On 3 July 2013 23:19, Joshua Landau wrote: >> If you don't want to do that, you'd need to use introspection of a >> remarkably hacky sort. If you want that, well, it'll take a mo. > > After some effort I'm pretty confident that the hacky way is impossible. Well, technical

Re: Default scope of variables

2013-07-03 Thread Peter Otten
Steven D'Aprano wrote: > Well, if I ever have more than 63,000,000 variables[1] in a function, > I'll keep that in mind. Until then, I'm pretty sure you can trivially > avoid name clashes with globals that you wish to avoid clashing with. > [1] Based on empirical evidence that Python supports nam

Re: Default scope of variables

2013-07-04 Thread Peter Otten
Rotwang wrote: > Sorry to be OT, but this is sending my pedantry glands haywire: We are mostly pedants, too -- so this is well-deserved... > On 04/07/2013 08:06, Dave Angel wrote: >> On 07/04/2013 01:32 AM, Steven D'Aprano wrote: >>> >> >>> >>> Well, if I ever have more than 63,000,000

Re: Simple recursive sum function | what's the cause of the weird behaviour?

2013-07-06 Thread Peter Otten
Russel Walker wrote: > Since I've already wasted a thread I might as well... > > Does this serve as an acceptable solution? > > def supersum(sequence, start=0): > result = type(start)() > for item in sequence: > try: > result += supersum(item, start) > except:

Re: UnpicklingError: NEWOBJ class argument isn't a type object

2013-07-08 Thread Peter Otten
skunkwerk wrote: > Hi, > I'm using a custom pickler that replaces any un-pickleable objects (such > as sockets or files) with a string representation of them, based on the > code from Shane Hathaway here: > http://stackoverflow.com/questions/4080688/python-pickling-a-dict-with- some-unpickla

Re: UnpicklingError: NEWOBJ class argument isn't a type object

2013-07-09 Thread Peter Otten
skunkwerk wrote: > On Monday, July 8, 2013 12:45:55 AM UTC-7, Peter Otten wrote: >> skunkwerk wrote: >> >> >> >> > Hi, >> >> > I'm using a custom pickler that replaces any un-pickleable objects >> > (such >> >

Re: Callable or not callable, that is the question!

2013-07-11 Thread Peter Otten
Ulrich Eckhardt wrote: > Hello! > > I just stumbled over a case where Python (2.7 and 3.3 on MS Windows) > fail to detect that an object is a function, using the callable() > builtin function. Investigating, I found out that the object was indeed > not callable, but in a way that was very unexpec

Re: Callable or not callable, that is the question!

2013-07-12 Thread Peter Otten
Steven D'Aprano wrote: > On Fri, 12 Jul 2013 07:36:30 +, Duncan Booth wrote: > >> To be a convincing use-case you would have to show a situation where >> something had to be both a static method and a utility method rather >> than just one or the other and also where you couldn't just have bo

Re: Understanding other people's code

2013-07-12 Thread Peter Otten
L O'Shea wrote: > Hi all, > I've been asked to take over a project from someone else and to extend the > functionality of this. The project is written in Python which I haven't > had any real experience with (although I do really like it) so I've spent > the last week or two settling in, trying to

Re: RE Module Performance

2013-07-12 Thread Peter Otten
Joshua Landau wrote: > On 12 July 2013 11:45, Devyn Collier Johnson > wrote: >> Could you explain what you mean? What and where is the new Flexible >> String Representation? > > Do not worry. jmf is on about his old rant comparing broken previous > versions of Python to newer ones which in some

Re: help with explaining how to split a list of tuples into parts

2013-07-13 Thread Peter Otten
pe...@ifoley.id.au wrote: > Hi List, > > I am new to Python and wondering if there is a better python way to do > something. As a learning exercise I decided to create a python bash > script to wrap around the Python Crypt library (Version 2.7). > > My attempt is located here - https://gist.git

Re: tkinter redraw rates

2013-07-17 Thread Peter Otten
fronag...@gmail.com wrote: > Hm. My apologies for not being very clear. What I'm doing is this: > > self.loader_thread = Thread(target=self.loadpages, > name="loader_thread") > self.loader_thread.start() > while self.loader_thread.isAliv

Re: How can I make this piece of code even faster?

2013-07-21 Thread Peter Otten
pablobarhamal...@gmail.com wrote: > Ok, I'm working on a predator/prey simulation, which evolve using genetic > algorithms. At the moment, they use a quite simple feed-forward neural > network, which can change size over time. Each brain "tick" is performed > by the following function (inside the

Re: odd behavoiur seen

2013-07-22 Thread Peter Otten
Chris Hinsley wrote: > On 2013-07-22 18:36:41 +, Chris Hinsley said: > >> Folks, I have this decorator: >> >> def memoize(maxsize): >> def _memoize(func): >> lru_cache = {} >> lru_list = [] > > Other clues, I use it on a recursive function: > > @memoize(64) > def next_m

Re: How to tick checkboxes with the same name?

2013-07-23 Thread Peter Otten
malay...@gmail.com wrote: > I faced a problem: to implement appropriate search program I need to tick > few checkboxes which turned out to have the same name (name="a", > id="a1","a2","a3","a4"). Set_input('a', True) does not work (I use Grab > library), For all but the most popular projects a u

Re: Beginner. 2d rotation gives unexpected results.

2013-07-23 Thread Peter Otten
en...@yandex.ru wrote: > This is my first post, nice to meet you all! Welcome! > I`m biology student from Russia, trying to learn python to perform some > > simple simulations. > > Here`s my first problem. > I`m trying to perform some simple 2d vector rotations in pygame, in order > > to lear

Re: Python 3: dict & dict.keys()

2013-07-23 Thread Peter Otten
Ethan Furman wrote: > So, my question boils down to: in Python 3 how is dict.keys() different > from dict? What are the use cases? I just grepped through /usr/lib/python3, and could not identify a single line where some_object.keys() wasn't either wrapped in a list (or set, sorted, max) call,

Re: Python 3: dict & dict.keys()

2013-07-24 Thread Peter Otten
Oscar Benjamin wrote: > On Jul 24, 2013 7:25 AM, "Peter Otten" <__pete...@web.de> wrote: >> >> Ethan Furman wrote: >> >> > So, my question boils down to: in Python 3 how is dict.keys() >> > different >> > from dict? What are t

Re: Python 3: dict & dict.keys()

2013-07-25 Thread Peter Otten
Chris Angelico wrote: > On Thu, Jul 25, 2013 at 5:04 PM, Steven D'Aprano > wrote: >> - Views support efficient (O(1) in the case of keys) membership testing, >> which neither iterkeys() nor Python2 keys() does. > > To save me the trouble and potential error of digging through the > source code:

Re: Python 3: dict & dict.keys()

2013-07-25 Thread Peter Otten
Ian Kelly wrote: > On Thu, Jul 25, 2013 at 2:13 AM, Peter Otten <__pete...@web.de> wrote: >> Chris Angelico wrote: >> >>> On Thu, Jul 25, 2013 at 5:04 PM, Steven D'Aprano >>> wrote: >>>> - Views support efficient (O(1) in the case of key

Re: Help

2013-07-25 Thread Peter Otten
ty...@familyrobbins.com wrote: > I'm a bit new to python and I'm trying to create a simple program which > adds words and definitions to a list, and then calls them forward when > asked to. > while escape < 1: > > choice = input("Type 'Entry' to add a word to the Dictionary, 'Search' > t

Re: How to tick checkboxes with the same name?

2013-07-26 Thread Peter Otten
malay...@gmail.com wrote: > вторник, 23 июля 2013 г., 11:25:00 UTC+4 пользователь Peter Otten написал: >> malay...@gmail.com wrote: >> For all but the most popular projects a url works wonders. I'm assuming >> http://grablib.org > Well, I have read the documentat

Re: python import module question

2013-07-28 Thread Peter Otten
syed khalid wrote: > I am trying to do a "import shogun" in my python script. I can invoke > shogun with a command line with no problem. But I cannot with a python > import statement. > >>invoking python from a command line... > > Syedk@syedk-ThinkPad-T410:~/shogun-2.0.0/src/interfac

RE: sqlite3 version lacks instr

2013-07-28 Thread Peter Otten
Joseph L. Casale wrote: >> Has anyone encountered this and utilized other existing functions >> within the shipped 3.6.21 sqlite version to accomplish this? > > Sorry guys, forgot about create_function... Too late, I already did the demo ;) >>> import sqlite3 >>> db = sqlite3.connect(":memory:"

Re: Bitwise Operations

2013-07-29 Thread Peter Otten
Devyn Collier Johnson wrote: > On Python3, how can I perform bitwise operations? For instance, I want > something that will 'and', 'or', and 'xor' a binary integer. >>> 0b1010 | 0b1100 14 >>> bin(_) '0b1110' >>> 0b1010 & 0b1100 8 >>> bin(_) '0b1000' >>> 0b1010 ^ 0b1100 6 >>> bin(_) '0b110' --

Re: Python descriptor protocol (for more or less structured data)

2013-07-30 Thread Peter Otten
CWr wrote: > Some years ago I started a small WSGI project at my university. Since then > the project was grown up every year. Some classes have more than 600 lines > of code with (incl. boiler-plates mostly in descriptors/properties). > > Many of these properties are similar or have depencies am

Re: "constant sharing" works differently in REPL than in script ?

2012-06-18 Thread Peter Otten
shearich...@gmail.com wrote: > Listening to 'Radio Free Python' episode 8 > (http://radiofreepython.com/episodes/8/ - around about the 30 minute mark) > I heard that Python pre creates some integer constants to avoid a > proliferation of objects with the same value. > > I was interested in this a

Re: Converting html character codes to utf-8 text

2012-06-19 Thread Peter Otten
Johann Spies wrote: > I am trying the following: > > Change data like this: > > Bien Donné : agri tourism > > to this: > > Bien Donné agri tourism > > I am using the 'unescape' function published on > http://effbot.org/zone/re-sub.htm#unescape-html but working through a file > I get the follo

Re: cPickle - sharing pickled objects between scripts and imports

2012-06-23 Thread Peter Otten
Rotwang wrote: > Hi all, I have a module that saves and loads data using cPickle, and > I've encountered a problem. Sometimes I want to import the module and > use it in the interactive Python interpreter, whereas sometimes I want > to run it as a script. But objects that have been pickled by runn

Re: Getting lazy with decorators

2012-06-24 Thread Peter Otten
Josh English wrote: > I'm creating a cmd.Cmd class, and I have developed a helper method to > easily handle help_xxx methods. > > I'm trying to figure out if there is an even lazier way I could do this > with decorators. > > Here is the code: > * > import cmd > > > def add_

Re: Why is python source code not available on github?

2012-06-24 Thread Peter Otten
gmspro wrote: > Why is python source code not available on github? > > Make it available on github so that we can git clone and work on source > code. http://thread.gmane.org/gmane.comp.python.devel/121885/focus=122111 -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting lazy with decorators

2012-06-26 Thread Peter Otten
Josh English wrote: > On Sunday, June 24, 2012 1:07:45 AM UTC-7, Peter Otten wrote: >> >> You cannot access a class instance because even the class itself doesn't >> exist yet. You could get hold of the class namespace with >> sys._getframe(), >> >&

Re: Getting lazy with decorators

2012-06-26 Thread Peter Otten
Peter Otten wrote: >>>helpfunc = getattr(self, "do_" + name[5:]).help > > i. e. it looks for getattr(self, "do_help") which does exist and then Sorry that should be getattr(self, "do_done"). -- http://mail.python.org/mailman/listinfo/python-list

Re: code review

2012-06-30 Thread Peter Otten
Alister wrote: > I think I may be on firmer grounds with the next few: > > isValidPassword can be simplified to > > def isValidPassword(password: > count=len(password) > return count>= mud.minpass and count<= mud.maxpass > > ( I used count to save finding the length of password

Re: hello everyone! i'm a new member from China

2012-07-02 Thread Peter Otten
levi nie wrote: > i love python very much.it's powerful,easy and useful. > i got it from Openstack.And i'm a new guy on python. Welcome! > Can i ask some stupid questions in days? haha... Sure, but we cannot guarantee that the answer will be stupid, too ;) -- http://mail.python.org/mailman/li

  1   2   3   4   5   6   7   8   9   10   >