Re: better way for ' '.join(args) + '\n'?

2012-10-26 Thread Peter Otten
Ulrich Eckhardt wrote: > Hi! > > General advise when assembling strings is to not concatenate them > repeatedly but instead use string's join() function, because it avoids > repeated reallocations and is at least as expressive as any alternative. > > What I have now is a case where I'm assemblin

Re: Nice solution wanted: Hide internal interfaces

2012-10-29 Thread Peter Otten
Johannes Bauer wrote: > Now I want A to call some private methods of B and vice versa (i.e. what > C++ "friends" are), but I want to make it hard for the user to call > these private methods. > > Currently my ugly approach is this: I delare the internal methods > private (hide from user). Then I

Re: Nice solution wanted: Hide internal interfaces

2012-10-29 Thread Peter Otten
Johannes Bauer wrote: > On 29.10.2012 17:52, Grant Edwards wrote: > >> By "decleare them privide" do you mean using __ASDF__ name-munging? >> >> It sounds to me like you're just making life hard on yourself. > > Gaah, you are right. I just noticed that using the single underscore > (as I do

Re: Organisation of python classes and their methods

2012-11-02 Thread Peter Otten
Martin Hewitson wrote: > Dear list, > > I'm relatively new to Python and have googled and googled but haven't > found a reasonable answer to this question, so I thought I'd ask it here. > > I'm beginning a large Python project which contains many packages, modules > and classes. The organisation

Re: Organisation of python classes and their methods

2012-11-02 Thread Peter Otten
Martin Hewitson wrote: > > On 2, Nov, 2012, at 09:00 AM, Peter Otten <__pete...@web.de> wrote: > >> Martin Hewitson wrote: >> >>> Dear list, >>> >>> I'm relatively new to Python and have googled and googled but haven't >>

Re: Organisation of python classes and their methods

2012-11-02 Thread Peter Otten
Martin Hewitson wrote: > On 2, Nov, 2012, at 09:40 AM, Mark Lawrence > wrote: >> 20 lines of documentation per method? As far as I'm concerned that's not >> a smell, that's a stink. > > Wow, I don't think I've ever been criticised before for writing too much > documentation :) > > I guess we

enabling universal newline

2012-11-02 Thread Peter Kleiweg
abled. Why is this? -- Peter Kleiweg http://pkleiweg.home.xs4all.nl/ -- http://mail.python.org/mailman/listinfo/python-list

Re: enabling universal newline

2012-11-03 Thread Peter Otten
Steven D'Aprano wrote: > On Fri, 02 Nov 2012 23:22:53 +0100, Peter Kleiweg wrote: > >> In Python 3.1 and 3.2 >> >> At start-up, the value of sys.stdin.newlines is None, which means, >> universal newline should be enabled. But it isn't. > > What ma

Re: enabling universal newline

2012-11-03 Thread Peter Kleiweg
Steven D'Aprano schreef op de 2e dag van de slachtmaand van het jaar 2012: > On Fri, 02 Nov 2012 23:22:53 +0100, Peter Kleiweg wrote: > > > In Python 3.1 and 3.2 > > > > At start-up, the value of sys.stdin.newlines is None, which means, > > universal newl

Re: accepting file path or file object?

2012-11-05 Thread Peter Otten
andrea crotti wrote: > Quite often I find convenient to get a filename or a file object as > argument of a function, and do something as below: > > def grep_file(regexp, filepath_obj): > """Check if the given text is found in any of the file lines, take > a path to a file or an opened fil

Re: accepting file path or file object?

2012-11-05 Thread Peter Otten
andrea crotti wrote: > 2012/11/5 Peter Otten <__pete...@web.de>: >> I sometimes do something like this: >> @contextmanager >> def xopen(file=None, mode="r"): >> if hasattr(file, "read"): >> yield file elif file == &qu

Re: Logging output to be redirected to a particular folder

2012-11-06 Thread Peter Otten
anuradha.raghupathy2...@gmail.com wrote: > Hi, > > Below is the python code that I have. I want to redirect the output to my > C drive..myapp.log. > > I am editing and creating scripts in IDLE and running it as a python shell > or module. > > Can you help? > > import logging > > def main(): >

Re: clicking on turtle

2012-11-07 Thread Peter Otten
Nicolas Graner wrote: > I have a problem with the standard "turtle" module. When a turtle has > a custom shape of type "compound", it doesn't seem to respond to click > events. No problem with polygon shapes. > > Running python 3.2.3, turtle version 1.1b on Windows XP. > > Here is my test file:

Re: Pickling a dictionary

2012-11-07 Thread Peter Otten
Devashish Tyagi wrote: > So I want to store the current state of a InteractiveInterpreter Object in > database. In order to achieve this I tried this > > obj = InteractiveInterpreter() > local = obj.locals() > pickle.dump(local, open('obj.dump','rw')) Assuming InteractiveInterpreter is imported

Re: Read number of CSV files

2012-11-08 Thread Peter Otten
Smaran Harihar wrote: > I am able to read through a CSV File and fetch the data inside the CSV > file but I have a really big list of CSV files and I wish to do the same > particular code in all the CSV files. > > Is there some way that I can loops through all these files, which are in a > single

Re: Unconverted data remains

2012-11-08 Thread Peter Otten
Nikhil Verma wrote: > I have a list :- > L = ['Sunday November 11 2012 9:00pm ', 'Thursday November 15 2012 > 7:00pm ',\ [...] > 2012 7:00pm '] > final_event_time = [datetime.strptime(iterable, '%A %B %d %Y %I:%M%p') for > iterable in L] > > and having this error Unconverted data remains .

Re: isinstance(.., file) for Python 3

2012-11-08 Thread Peter Otten
Ulrich Eckhardt wrote: > Hi! > > I have two problems that are related and that I'd like to solve together. > > Firstly, I have code that allows either a file or a string representing > its content as parameter. If the parameter is a file, the content is > read from the file. In Python 2, I used

Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-10 Thread Peter Otten
Miki Tebeka wrote: >> Is there a simpler way to modify all arguments in a function before using >> the arguments? > You can use a decorator: > > from functools import wraps > > def fix_args(fn): > @wraps(fn) > def wrapper(*args): > args = (arg.replace('_', '') for arg in args) >

Re: Want to add dictionary keys to namespace?

2012-11-10 Thread Peter Otten
Jeff Jeffries wrote: > Smart people, Is there a way I can add a dictionaries keys to the python > namespace? It would just be temporary as I am working with a large > dictionary, and it would speed up work using an IDE. I look and find > nothing... none of the keys have spaces and none are common

Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-11 Thread Peter Otten
Aahz wrote: > In article , > Peter Otten <__pete...@web.de> wrote: >>Miki Tebeka wrote: >> >>>> Is there a simpler way to modify all arguments in a function before >>>> using the arguments? >>> >>> You can use a decora

Re: A gnarly little python loop

2012-11-11 Thread Peter Otten
Paul Rubin wrote: > Cameron Simpson writes: >> | I'd prefer the original code ten times over this inaccessible beast. >> Me too. > > Me, I like the itertools version better. There's one chunk of data > that goes through a succession of transforms each of which > is very straightforward. [Steve

Re: A gnarly little python loop

2012-11-11 Thread Peter Otten
Steve Howell wrote: > On Nov 11, 1:09 am, Paul Rubin wrote: >> Cameron Simpson writes: >> > | I'd prefer the original code ten times over this inaccessible beast. >> > Me too. >> >> Me, I like the itertools version better. There's one chunk of data >> that goes through a succession of transform

Re: logging, can one get it to email messages over a certain level?

2012-11-12 Thread Peter Otten
tinn...@isbd.co.uk wrote: > Steve Howell wrote: >> On Nov 11, 9:48 am, tinn...@isbd.co.uk wrote: >> > I'm sure this must be possible but at the moment I can't see how to do >> > it. >> > >> > I want to send an E-Mail when the logging module logs a message above >> > a certain level (probably for

Re: Is there a way to creat a func that returns a cursor that can be used?

2012-11-12 Thread Peter Otten
Khalid Al-Ghamdi wrote: > Is there a way to create a func that returns a cursor that can be used to > execute sql statements? You should read an introductory text on Python, this is not specific to sqlite3. > I tried this (after importing sqlite3), but it gave me the error below: > def c

Re: A gnarly little python loop

2012-11-12 Thread Peter Otten
rusi wrote: > The fidgetiness is entirely due to python not allowing C-style loops > like these: > >>> while ((c=getchar()!= EOF) { ... } for c in iter(getchar, EOF): ... > Clearly the fidgetiness is there as before and now with extra coroutine > plumbing Hmm, very funny... -- http://mai

Re: Read number of CSV files

2012-11-12 Thread Peter Otten
Peter Otten wrote: [please don't email me directly] > How is using glob different from os.listdir() Peter? glob retains the path and allows you to filter the files. Compare: >>> import os, glob >>> os.listdir("alpha") ['one.py', 'tw

Re: Understanding Code

2012-11-13 Thread Peter Otten
subhabangal...@gmail.com wrote: > Dear Group, > To improve my code writing I am trying to read good codes. Now, I have > received a code,as given below,(apology for slight indentation errors) the > code is running well. Now to comprehend the code, I am looking to > understand it completely. > > c

Re: Passing functions as parameter (multiprocessing)

2012-11-13 Thread Peter Otten
Jean-Michel Pichavant wrote: > I'm having problems understanding an issue with passing function as > parameters. > Here's a code that triggers the issue: > > > import multiprocessing > > def f1(): > print 'I am f1' > def f2(foo): > print 'I am f2 %s' % foo > > workers = [ > (

Re: Passing functions as parameter (multiprocessing)

2012-11-13 Thread Peter Otten
Oscar Benjamin wrote: > I don't know if this is to do with the way that the code was > simplified before posting but this subproc function wrapper does > nothing (even after Peter fixed it below). This code is needlessly > complicated for what it does. Jean-Michel's

Re: Path Browser seems to be broken

2012-11-20 Thread Peter Otten
Daniel Klein wrote: > If you try to expand any of the paths in the Path Browser (by clicking the > + sign) then it not only closes the Path Browser but it also closes all > other windows that were opened in IDLE, including the IDLE interpreter > itself. > > A Google search doesn't look like this

Re: method that can be called from a class and also from an instance

2012-11-22 Thread Peter Otten
Marc Aymerich wrote: > Hi, > > I want to create a method within a class that is able to accept either a > class or an instance. > > class MyClass(object): > @magic_decorator > def method(param): > # param can be MyClass (cls) or an instance of MyClass (self) > > so I can do some

Re: PyPy 2.0 beta 1 released

2012-11-22 Thread Peter Funk
e? Regards, Peter Funk -- Peter Funk, home: ✉Oldenburger Str.86, D-2 Ganderkesee mobile:+49-179-640-8878 phone:+49-421-20419-0 <http://www.artcom-gmbh.de/> office: ArtCom GmbH, ✉Haferwende 2, D-28357 Bremen, Germany -- http://mail.python.org/mailman/listinfo/python-list

Re: method that can be called from a class and also from an instance

2012-11-23 Thread Peter Otten
Steven D'Aprano wrote: > On Thu, 22 Nov 2012 16:51:27 +0100, Peter Otten wrote: > >> Marc Aymerich wrote: >> >>> Hi, >>> >>> I want to create a method within a class that is able to accept either >>> a class or an instance. > [...

Re: Migrate from Access 2010 / VBA

2012-11-23 Thread Peter Otten
kgard wrote: > Greetings: > > I am the lone developer of db apps at a company of 350+ employees. > Everything is done in MS Access 2010 and VBA. I'm frustrated with the > limitations of this platform and have been considering switching to > Python. I've been experimenting with the language for a

Re: python3.3 - tk_setPalette bug?

2012-11-23 Thread Peter Otten
Helmut Jarausch wrote: > Hi, > > AFAIK, this should work: > > import tkinter as Tk > root= Tk.Tk() > root.tk_setPalette(background = 'AntiqueWhite1', foreground = 'blue') > > but python-3.3:0e4574595674+ gives > > Traceback (most recent call last): > File "Matr_Select.py", line 174, in >

Re: how to split the file into two sections....

2012-12-04 Thread Peter Otten
indu_shreen...@yahoo.co.in wrote: > Hi: > I have a text as > version comp X - aa > version comp Y - bbb > version comp Z -cc > > 12.12 Check for option 1 > > 12:13 Pass Test 1 > 12:14 verified bla bla bla > 12.15 completed > > 12.16 Fail Test 2 > 12:17 verified bla bla bla > 12.18 completed >

RE: Dict comprehension help

2012-12-06 Thread Peter Otten
Joseph L. Casale wrote: [Ian Kelly] >> {k: v for d in my_list if d['key'] == value for (k, v) in d.items()} > > Ugh, had part of that backwards:) Nice! > >> However, since you say that all dicts have a unique value for >> z['key'], you should never need to actually merge two dicts, correct? >> I

Re: wrong ImportError message printed by python3.3 when it can't find a module?

2012-12-07 Thread Peter Otten
Irmen de Jong wrote: > I'm seeing that Python 3.3.0 is not printing the correct ImportError when > it can't import a module that is imported from another module. Instead of > printing the name of the module it can't import, it prints the name of the > module that is doing the faulty import. > > B

Re: Help with Singleton SafeConfigParser

2012-12-08 Thread Peter Otten
Josh English wrote: > I have seen older posts in this group that talk about using modules as singletons, but this, unless I misunderstand, requires me to code the entire API for SafeConfigParser in the module: > > > import ConfigParser > > > class Options(ConfigParser.SafeConfigParser): >

Re: why the conut( ) can not get the number?

2012-12-10 Thread Peter Otten
水静流深 wrote: > i wnat to get the number of a atrributes in a xpath,here is my code,why i > can not get the number ? import urllib > import lxml.html > down="http://python-gtk-3-tutorial.readthedocs.org/en/latest/index.html"; > file=urllib.urlopen(down).read() > root=lxml.html.document_fromstring(f

Re: About open file for Read

2012-12-10 Thread Peter Otten
Dave Angel wrote: > On 12/10/2012 11:36 AM, moonhkt wrote: >> Hi All >> >> I am new in Python. When using open and then for line in f . >> >> Does it read all the data into f object ? or read line by line ? >> >> >> f=open(file, 'r') >>for line in f: >> if userstring in

Re: String manipulation in python..NEED HELP!!!!

2012-12-11 Thread Peter Pearson
On Tue, 11 Dec 2012 16:39:27 +, duncan smith wrote: [snip] > >>> alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" > >>> key = "XPMGTDHLYONZBWEARKJUFSCIQV" > >>> mapping = {} > >>> for i, ch in enumerate(alpha): > mapping[ch] = key[i] mapping = dict(zip(alpha, key)) -- To email me, substitute nowhe

Re: Hollow square program

2012-12-12 Thread Peter Otten
siimnur...@gmail.com wrote: > Well, I did some modifications and got a hollow square, but the columns > aren't perfectly aligned with the rows (at least if input is 5. Thanks for > the help :) > > rows = int(input()) > s1="* "*rows > s2="*"+(rows-2)*" "+"*" > print(s1) > for s in range(rows-2): >

Re: How to import module whose filename starts number

2012-12-12 Thread Peter Otten
Yong Hu wrote: > I have a few scripts whose file names start with numbers. For example, > 01_step1.py, 02_step2.py > > I tried to import them in another script by "import 01_step1" or "from > 01_step1 import *". Both failed, saying "SyntaxError: invalid syntax" > > Is there anyway to import thos

Re: Find lowest level directory

2012-12-13 Thread Peter Otten
loial wrote: > How can I find the full path of the lowest level directory in a directory > structure? > > If there is more than one directory at the lowest level, the first one > found will be enough. import os def directories(root): for path, folders, files in os.walk(root): for n

Re: unpacking first few items of iterable

2012-12-13 Thread Peter Otten
Terry Reedy wrote: > On 12/13/2012 3:09 PM, MRAB wrote: >> On 2012-12-13 19:37, Daniel Fetchinson wrote: >>> Hi folks, I swear I used to know this but can't find it anywhere: >>> >>> What's the standard idiom for unpacking the first few items of an >>> iterable whose total length is unknown? > >

Re: Is it possible monkey patch like this?

2012-12-18 Thread Peter Otten
Marc Aymerich wrote: > Dear all, > I want to monkey patch a method that has lots of code so I want to avoid > copying all the original method for changing just two lines. The thing is > that I don't know how to do this kind of monkey patching. > > Consider the following code: > > class Oringinal

Re: [newbie] problem making equally spaced value array with linspace

2012-12-18 Thread Peter Otten
Jean Dubois wrote: > I have trouble with the code beneath to make an array with equally > spaced values > When I enter 100e-6 as start value, 700e-6 as end value and 100e-6 I > get the following result: > [ 0.0001 0.00022 0.00034 0.00046 0.00058 0.0007 ] > But I was hoping for: > [ 0.0001

Re: Pattern-match & Replace - help required

2012-12-19 Thread Peter Otten
AT wrote: > I am new to python and web2py framework. Need urgent help to match a > pattern in an string and replace the matched text. > > I've this string (basically an sql statement): > stmnt = 'SELECT taxpayer.id, > taxpayer.enc_name, > taxpayer.age, > taxpayer.occup

Re: Strange effect with import

2012-12-20 Thread Peter Otten
Jens Thoms Toerring wrote: > Hi, > >I hope that this isn't a stupid question, asked already a > hundred times, but I haven't found anything definitive on > the problem I got bitten by. I have two Python files like > this: > > S1.py -- > import random > import S2 > > class R( ob

Re: Second try: non-blocking subprocess pipe and Tkinter in 2.7

2012-12-21 Thread Peter Otten
Kevin Walzer wrote: > Yesterday I posted a question about keeping a Tkinter GUI during a > long-running process, i.e. reading data from a pipe via the subprocess > module. I think that question did not quite get at the heart of the > issue because it assumed that Python, like Tcl which underlies T

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-22 Thread Peter Otten
prilisa...@googlemail.com wrote: > Hello, to all, > > I hope I can describe me problem correctly. > > I have written a Project split up to one Main.py and different modules > which are loaded using import and here is also my problem: > > 1. Main.py executes: > 2. Import modules > 3. One of the

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-22 Thread Peter Otten
prilisa...@googlemail.com wrote: > I don't know, Python allways looks for me like a one script "File". But > there are big projects. like the the "Model of an SQL Server", using > coordinators no problems running threads and exchange Data through a > Backbone. I have searched a lot, but I havent f

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-23 Thread Peter Otten
prilisa...@googlemail.com wrote: > Thanks to all your answers, I have read a lot about namespaces, but still > there's something I do not understood. I have tried your example but as I > expected: > > line 13, in HandoverSQLCursor > curs.execute("SELECT * FROM lager") > AttributeError: 'built

Re: EOFError why print(e) cannot print out any information ?

2012-12-26 Thread Peter Otten
iMath wrote: > f = open('UsersInfo.bin','rb') > while True: > try: > usrobj = pickle.load(f) > except EOFError as e: > print(e) > break > else: > usrobj.dispuser() > f.close() > why print(e) cannot print out

Re: pickle module doens't work

2012-12-27 Thread Peter Otten
Omer Korat wrote: > I'm working on a project in Python 2.7. I have a few large objects, and I > want to save them for later use, so that it will be possible to load them > whole from a file, instead of creating them every time anew. It is > critical that they be transportable between platforms. P

Re: Creating an iterator in a class

2012-12-27 Thread Peter Otten
Joseph L. Casale wrote: > I am writing a class to provide a db backed configuration for an > application. > > In my programs code, I import the class and pass the ODBC params to the > class for its __init__ to instantiate a connection. > > I would like to create a function to generically access

Re: Password hash

2012-12-27 Thread Peter Pearson
On Sun, 23 Dec 2012 20:38:12 -0600, Robert Montgomery wrote: > I am writing a script that will send an email using an account I set up > in gmail. It is an smtp server using tls on port 587, and I would like > to use a password hash in the (python) script for login rather than > plain text. Is this

Re: Wrapping statements in Python in SPSS

2012-12-28 Thread Peter Otten
alankrin...@gmail.com wrote: > I tried placing in the format you suggested and received this error > message: > > END PROGRAM. > Traceback (most recent call last): > File "", line 396, in > ValueError: incomplete format key You seem to have a malformed format string. Example: Correct: >>> "

Re: Confused about logger config from within Python (3)

2012-12-28 Thread Peter Otten
andrew cooke wrote: > similarly, if i run the following, i see only "done": > > from logging import DEBUG, root, getLogger > > if __name__ == '__main__': > root.setLevel(DEBUG) > getLogger(__name__).debug("hello world") > print('done') You need a handler. The easiest way t

Re: dict comprehension question.

2012-12-29 Thread Peter Otten
Quint Rankid wrote: > Newbie question. I've googled a little and haven't found the answer. > > Given a list like: > w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1] > I would like to be able to do the following as a dict comprehension. > a = {} > for x in w: > a[x] = a.get(x,0) + 1 > results in a having t

Re: Noob trying to parse bad HTML using xml.etree.ElementTree

2012-12-30 Thread Peter Otten
Morten Guldager wrote: > 'Aloha Friends! > > I'm trying to process some HTML using xml.etree.ElementTree > Problem is that the HTML I'm trying to read have some not properly closed > tags, as the shown in line 8 below. > > 1 from xml.etree import ElementTree > 2 > 3 tree = ElementTree >

Re: Beginner: Trying to get REAL NUMBERS from %d command

2012-12-30 Thread Peter Otten
Alvaro Lacerda wrote: > The code I wrote is supposed to ask the user to enter a number; > Then tell the user what's going to happen to that number (x / 2 + 5) ; > Then give the user an answer; > > I succeeded getting results from even numbers, but when I try diving an > uneven number (i.e. 5) by

Re: pygame - importing GL - very bad...

2013-01-01 Thread Peter Otten
someone wrote: > See this code (understand why I commented out first line): > > # from OpenGL.GL import * > from OpenGL.GL import glEnable, GL_DEPTH_TEST, \ > glShadeModel, GL_SMOOTH, glClearColor, \ > GL_CULL_FACE, GL_BLEND, glBlendFunc, \ > GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA

pylint, was Re: pygame - importing GL - very bad...

2013-01-02 Thread Peter Otten
someone wrote: > On 01/01/2013 01:56 PM, Peter Otten wrote: >> from module import * # pylint: disable=W0622 > > Oh, I just learned something new now... How come I cannot type "#pylint: > enable=W0622" in the line just below the import ? With what intended effect

Re: pylint, was Re: pygame - importing GL - very bad...

2013-01-03 Thread Peter Otten
Terry Reedy wrote: >> [a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with an >> underscore ? > > No, it allows underscores. As I read that re, 'rx', etc, do match. They No, it's one leading letter or underscore [a-z_] plus at least two letters, underscores or digits [a-z0-9_]{

Regular expression syntax, was Re: pylint, was Re: pygame - importing GL - very bad...

2013-01-03 Thread Peter Otten
someone wrote: > On 01/03/2013 10:00 AM, Peter Otten wrote: >> Terry Reedy wrote: >> >>>> [a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with >>>> [an >>>> underscore ? >>> >>> No, it allows underscores. As

Re: Question on for loop

2013-01-03 Thread Peter Otten
subhabangal...@gmail.com wrote: > Dear Group, > If I take a list like the following: > > fruits = ['banana', 'apple', 'mango'] > for fruit in fruits: >print 'Current fruit :', fruit > > Now, > if I want variables like var1,var2,var3 be assigned to them, we may take, > var1=banana, > var2=ap

Re: Problem with Unicode char in Python 3.3.0

2013-01-06 Thread Peter Otten
Franck Ditter wrote: > I work on MacOS-X Lion and IDLE/Python 3.3.0 > I can't get the treble key (U1D11E) ! > "\U1D11E" > SyntaxError: (unicode error) 'unicodeescape' codec can't > decode bytes in position 0-6: end of string in escape sequence > > How can I display musical keys ? Try >>> "

Specifying two log files with one configuration file

2013-01-06 Thread Peter Steele
I want to configure the Python logging module to manage two separate log files, allowing me to do something like this: import logging import logging.config logging.config.fileConfig("mylogging.conf") root = logging.getLogger() test = logging.getLogger("test") root.debug("This is a message target

Re: functon invoke or not

2013-01-09 Thread Peter Otten
skyworld wrote: > Hi, > > I see someone's code as this: > > class ABC: > def __init__(self, env): > ... > self.jmpTable['batchQ']['submit_job'] = self.lsf_submit The bound method self.lsf_submit is not invoked in this line, it is stored for later use. >

Re: Regex not matching a string

2013-01-09 Thread Peter Otten
python.pro...@gmail.com wrote: > In the following code ,am trying to remove a multi line - comment that > contains "This is a test comment" for some reason the regex is not > matching.. can anyone provide inputs on why it is so? > def find_and_remove(haystack, needle): > pattern = re.compile(

Re: How to change colors of multiple widgets after hovering in Tkinter

2013-01-10 Thread Peter Otten
mountdoo...@gmail.com wrote: > I´m trying to make a script, which will change the background and > foreground color of widgets after hovering. > but when I hover on any button, nothing happens, they stay white. I know I > could use a function, but there would be two functions for every widget (1

Re: Move modules to submodules question

2013-01-11 Thread Peter Otten
joshua.kimb...@gmail.com wrote: > I have a set of utility modules that were all added to a folder called > (util_mods). Recently the set of modules grew to be too large and I've > been working on splitting it up into sets of sub modules, for example, > util_mods\set_a. The issue is that if I start

Re: Multiple disjoint sample sets?

2013-01-13 Thread Peter Otten
Roy Smith wrote: > I have a list of items. I need to generate n samples of k unique items > each. I not only want each sample set to have no repeats, but I also > want to make sure the sets are disjoint (i.e. no item repeated between > sets). > > random.sample(items, k) will satisfy the first c

Re: Making a logging handler that produces context.

2013-01-14 Thread Peter Otten
Antoon Pardon wrote: > I have some in house code for which I am considering replacing the > logging code with something that uses the logging module. > However there is one thing the in-house log code does, that seems > difficult to do with the logging module, provide some context. The > in-hous

Re: Using inner dict as class interface

2013-01-16 Thread Peter Otten
Steven D'Aprano wrote: > On Wed, 16 Jan 2013 15:42:42 +0100, Florian Lindner wrote: > >> Hello, >> >> I have a: >> >> class C: >>def __init__(self): >> d = dict_like_object_created_somewhere_else() >> >> def some_other_methods(self): >> pass >> >> >> class C should behave lik

Re: iterating over the lines of a file - difference between Python 2.7 and 3?

2013-01-17 Thread Peter Otten
Wolfgang Maier wrote: > I just came across an unexpected behavior in Python 3.3, which has to do > with file iterators and their interplay with other methods of file/IO > class methods, like readline() and tell(): Basically, I got used to the > fact that it is a bad idea to mix them because the it

RE: iterating over the lines of a file - difference between Python 2.7 and 3?

2013-01-17 Thread Peter Otten
Wolfgang Maier wrote: > What will my IO object return then when I read from it in Python 2.7? str > where Python3 gives bytes, and unicode instead of str ? This is what I > understood from the Python 2.7 io module doc. You can always double-check in the interpreter: >>> with open("tmp.txt", "w"

Re: Any built-in ishashable method ?

2013-01-18 Thread Peter Otten
Jean-Michel Pichavant wrote: > Hello people, > > Is there any built-in way to know if an object is a valid dictionary key ? > From what I know, the object must be hashable, and from the python doc, an > object is hashable if it has the __hash__ and (__cmp__ or __eq__) methods. > > http://docs.py

Re: Any built-in ishashable method ?

2013-01-18 Thread Peter Otten
Jean-Michel Pichavant wrote: > That brings me to another question, is there any valid test case where > key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design > flaw ? I don't think there is a use case for such a behaviour other than annoying your collegues ;) -- http://mail.

Sending a broadcast message using raw sockets

2013-01-18 Thread Peter Steele
I want to write a program in Python that sends a broadcast message using raw sockets. The system where this program will run has no IP or default route defined, hence the reason I need to use a broadcast message. I've done some searches and found some bits and pieces about using raw sockets in

Re: Any built-in ishashable method ?

2013-01-18 Thread Peter Otten
Kushal Kumaran wrote: > Peter Otten <__pete...@web.de> writes: > >> Jean-Michel Pichavant wrote: >> >>> That brings me to another question, is there any valid test case where >>> key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design

Re: Safely add a key to a dict only if it does not already exist?

2013-01-19 Thread Peter Otten
Vito De Tullio wrote: > Chris Rebert wrote: > >>> How can I add a key in a thread-safe manner? >> I'm not entirely sure, but have you investigated dict.setdefault() ? > > but how setdefault makes sense in this context? It's used to set a default > value when you try to retrieve an element from t

Re: Any built-in ishashable method ?

2013-01-19 Thread Peter Otten
Dave Angel wrote: > On 01/18/2013 07:06 AM, Peter Otten wrote: >> Jean-Michel Pichavant wrote: >> >>> That brings me to another question, is there any valid test case where >>> key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design >>>

Re: Sending a broadcast message using raw sockets

2013-01-21 Thread Peter Steele
On Monday, January 21, 2013 1:10:06 AM UTC-8, Rob Williscroft wrote: > Peter Steele wrote in > > news:f37ccb35-8439-42cd-a063-962249b44...@googlegroups.com in > > comp.lang.python: > > > I want to write a program in Python that sends a broadcast message > > using

Re: Sending a broadcast message using raw sockets

2013-01-22 Thread Peter Steele
I just tried running you code, and the "sendto" call fails with "Network is unreachable". That's what I expected, based on other tests I've done. That's why I was asking about how to do raw sockets, since tools like dhclient use raw sockets to do what they do. It can clearly be duplicated in Pyt

Re: Using filepath method to identify an .html page

2013-01-22 Thread Peter Otten
Ferrous Cranus wrote: > I insist, perhaps compeleld, to use a key to associate a number to a > filename. Would you help please? > > I dont know this is supposed to be written. i just know i need this: > > number = function_that_returns_a_number_out_of_a_string( > absolute_path_of_a_html_file) >

Re: Sending a broadcast message using raw sockets

2013-01-22 Thread Peter Steele
> http://www.secdev.org/projects/scapy/ > > > > On Jan 22, 2013 9:17 AM, "Peter Steele" wrote: > > I just tried running you code, and the "sendto" call fails with "Network is > unreachable". That's what I expected, based on othe

Re: Using filepath method to identify an .html page

2013-01-22 Thread Peter Otten
Ferrous Cranus wrote: > Τη Τρίτη, 22 Ιανουαρίου 2013 6:11:20 μ.μ. UTC+2, ο χρήστης Chris Angelico > έγραψε: >> all of it. You are asking something that is fundamentally >> impossible[1]. There simply are not enough numbers to go around. > Fundamentally impossible? > > Well > > OK: How abou

Re: Sending a broadcast message using raw sockets

2013-01-22 Thread Peter Steele
013 at 4:57 AM, Peter Steele wrote: > > > In fact, I have used scapy in the past, but I am working in a restricted > > environment and don't have this package available. It provides tones more > > than I really need anyway, and I figured a simple raw socket send/receiv

Re: Any algorithm to preserve whitespaces?

2013-01-23 Thread Peter Otten
Santosh Kumar wrote: > I am in a problem. > > words = line.split(' ') > > preserve whitespaces but the problem is it writes an additional line > after every line. Strip off the newline at the end of the line with: line = line.rstrip("\n") words = line.split(" ") -- http://mail.python.o

Re: Any algorithm to preserve whitespaces?

2013-01-23 Thread Peter Otten
Santosh Kumar wrote: > Yes, Peter got it right. > > Now, how can I replace: > > script, givenfile = argv > > with something better that takes argv[1] as input file as well as > reads input from stdin. > > By input from stdin, I mean that currently when I do `

Re: Any algorithm to preserve whitespaces?

2013-01-24 Thread Peter Otten
Santosh Kumar wrote: > On 1/24/13, Peter Otten <__pete...@web.de> wrote: >> Santosh Kumar wrote: >> >>> Yes, Peter got it right. >>> >>> Now, how can I replace: >>> >>> script, givenfile = argv >>> >>> wi

Re: Any algorithm to preserve whitespaces?

2013-01-24 Thread Peter Otten
Santosh Kumar wrote: > But I can; see: http://pastebin.com/ZGGeZ71r You have messed with your cat command -- it adds line numbers. Therefore the output of cat somefile | ./argpa.py differs from ./argpa.py somefile Try ./argpa.py < somefile to confirm my analysis. As to why your capitalisati

Re: Dict comp help

2013-01-24 Thread Peter Otten
Joseph L. Casale wrote: > Slightly different take on an old problem, I have a list of dicts, I need > to build one dict from this based on two values from each dict in the > list. Each of the dicts in the list have similar key names, but values of > course differ. > > > [{'a': 'xx', 'b': 'yy', '

Re: finding abc's

2013-01-25 Thread Peter Otten
lars van gemerden wrote: > Hi all, > > i was writing a function to determine the common base class of a number > classes: > > def common_base(classes): > if not len(classes): > return None > common = set(classes.pop().mro()) > for cls in classes: > common.intersection

Re: Retrieving an object from a set

2013-01-26 Thread Peter Otten
Vito De Tullio wrote: > MRAB wrote: > >> It turns out that both S & {x} and {x} & S return {x}, not {y}. > > curious. > > $ python > Python 2.7.3 (default, Jul 3 2012, 19:58:39) > [GCC 4.7.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. x = (1,2,3) >>

Re: numpy array operation

2013-01-29 Thread Peter Otten
C. Ng wrote: > Is there a numpy operation that does the following to the array? > > 1 2 ==> 4 3 > 3 4 2 1 How about >>> a array([[1, 2], [3, 4]]) >>> a[::-1].transpose()[::-1].transpose() array([[4, 3], [2, 1]]) Or did you mean >>> a.reshape((4,))[::-1].reshape((2,2)) ar

Re: Need some help confirming transactions using sha256

2013-01-31 Thread Peter Pearson
On Thu, 31 Jan 2013 08:43:03 -0800 (PST), kryptox.excha...@gmail.com wrote: > I'm wondering if anyone can help me as I can't seem to get > this to work. There is an online dice game that is > provably fair by calculating the 'dice roll' using using a > sha256 hash calculated against my transaction

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