Re: a *= b not equivalent to a = a*b

2016-08-26 Thread Peter Otten
mlzarathus...@gmail.com wrote: > Yes, I just worked that out. It's the integer math that's the problem. > > I guess this has been fixed in python 3, but unfortunately it seems that > most people are still using python 2. Note that you can get Python 3's default behaviour in Python 2 with from _

Re: Python 3 raising an error where Python 2 did not

2016-08-26 Thread Peter Otten
d...@forestfield.co.uk wrote: > In a program I'm converting to Python 3 I'm examining a list of divisor > values, some of which can be None, to find the first with a value greater > than 1. > > Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] > on win32 Type "help", "copy

Re: urllib2 timeout not working - stalls for an hour or so

2016-09-02 Thread Peter Otten
Sumeet Sandhu wrote: > Hi, > > I use urllib2 to grab google.com webpages on my Mac over my Comcast home > network. > > I see about 1 error for every 50 pages grabbed. Most exceptions are > ssl.SSLError, very few are socket.error and urllib2.URLError. > > The problem is - after a first exception

Re: Would like some thoughts on a grouped iterator.

2016-09-05 Thread Peter Otten
Antoon Pardon wrote: > I need an interator that takes an already existing iterator and > divides it into subiterators of items belonging together. > > For instance take the following class, wich would check whether > the argument is greater or equal to the previous argument. > > class upchecker:

Re: Would like some thoughts on a grouped iterator.

2016-09-05 Thread Peter Otten
Jussi Piitulainen wrote: > Antoon Pardon writes: > >> I need an interator that takes an already existing iterator and >> divides it into subiterators of items belonging together. >> >> For instance take the following class, wich would check whether >> the argument is greater or equal to the previ

Re: Class - error return

2016-09-06 Thread Peter Otten
Smith wrote: > you can help me ? Yes ;) But you might consider posting on python-tutor instead of python- list. > I can not understand where is the error in this script. It's always a good idea to state both what you expect and what you get instead explicitly, in plain english. > In [72]: day

Re: How to split value where is comma ?

2016-09-07 Thread Peter Pearson
On Wed, 7 Sep 2016 08:51:36 -0700 (PDT), Asad ur Rehman wrote: [snip] > sofia/external/1203632525,CS_EXECUTE, > Outbound Call, > 12036325259, > ,12036325259, > , > ,ACTIVE, > 9047125683, > 9047125683, > RECV, > 75a9d3ee-7511-11e6-a115-89a1f4981d2c, > vb-pmedia,7841c6c0-7511-11e6

Re: import pybel in python error code

2016-09-09 Thread Peter Otten
talari.gopiprashanth.go...@gmail.com wrote: > ValueErrorTraceback (most recent call > last) in () > 1 from django.conf import settings > > 2 import pybel > 3 import random, os > > C:\Miniconda2\lib\site-packages\pybel.py in () > 67 _obconv = o

Re: Mysterious Logging Handlers

2016-09-09 Thread Peter Otten
Josh English wrote: > I have a Python script that imports a utility script. Both scripts use > logging, but the logs don't work as advertised. I'm getting logging output > from the utility script but none from the main file. Worse, the format of > the utility script's logs don't match anything I d

Re: Override property setter of base class in Python 3 - USE CASE

2016-09-11 Thread Peter Otten
Nagy László Zsolt wrote: > >> Yes, I believe it does. (Others may disagree. This is a design >> question and very much a matter of style, not hard fact.) I would have >> an explicit action "set_content" which will set the value of an input >> field, the inner text of a textarea, the checked state

Re: iterating over multi-line string

2016-09-11 Thread Peter Otten
Doug OLeary wrote: > Hey; > > I have a multi-line string that's the result of reading a file filled with > 'dirty' text. I read the file in one swoop to make data cleanup a bit > easier - getting rid of extraneous tabs, spaces, newlines, etc. That > part's done. > > Now, I want to collect data

Re: more python3 regex?

2016-09-11 Thread Peter Otten
Doug OLeary wrote: > Hey > > This one seems like it should be easy but I'm not getting the expected > results. > > I have a chunk of data over which I can iterate line by line and print out > the expected results: > > for l in q.findall(data): > # if re.match(r'(Name|")', l): > # contin

Re: KeyError: 'handlers.RotatingFileHandler'

2016-09-12 Thread Peter Otten
Daiyue Weng wrote: > Hi, I am trying to use 'RotatingFileHandler' in a logging config file, > > import logging > import logging.config > import logging.handlers > > logging.config.fileConfig('logging.conf') > > > [loggers] > keys=root,ingestion_log > > [handlers] > keys=consoleHandler,fileHan

Re: Expected type 'optional[bytes]' got 'str' instead

2016-09-13 Thread Peter Otten
Daiyue Weng wrote: > Hi, I have the following piece of code, > > rootPath = os.path.abspath(__file__) > > rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit('\\', 1)[0] > > > PyCharm inspection gave me warning on argument '\\' of the 2nd rsplit, > > Expected type 'optional[bytes]' got 'str' inst

Re: Global variable is undefined at the module level

2016-09-13 Thread Peter Otten
Daiyue Weng wrote: > Hi, I defined a global variable in some function like this, > > def some_function(self): > > global global_var > > PyCharm inspection gave me, > > Global variable is undefined at the module level There is no single way to silence that complaint and actually improve y

Re: logging TypeError: not all arguments converted during string formatting

2016-09-15 Thread Peter Otten
Daiyue Weng wrote: > Hi, I am trying to record memory and CPU usages and load a logger from an > external config file (logging.conf), [snip] One important debugging strategy is to try and find the minimal example that produces a problem. In this case you can provoke the the behaviour you are s

Re: Expected type 'optional[bytes]' got 'str' instead

2016-09-16 Thread Peter Otten
> Daiyue Weng wrote: [Please answer to the mailing list instead of sending private emails] > On 13 September 2016 at 12:37, Peter Otten <__pete...@web.de> wrote: >> Daiyue Weng wrote: >>> Hi, I have the following piece of code, >>> >>> rootPath

Re: How to get the source code of python function being decorated?

2016-09-16 Thread Peter Otten
Peng Yu wrote: > Hi, See the following example, I am not able to get the source code of > the actual function that does the calculation of partial_ratio. Does > anybody know what is the correct way of getting the source? > > /tmp$ ./main.py > @functools.wraps(func) > def decorator(*args,

Re: Serialising an 8x8x8 array of pygame sounds

2016-09-18 Thread Peter Otten
kerbingamer376 wrote: > On Sunday, September 18, 2016 at 2:59:10 PM UTC+1, Steve D'Aprano wrote: >> On Sun, 18 Sep 2016 11:20 pm, kerbingamer376 wrote: >> >> > Is it possible to serialise an 8x8x8 array of pygame.mixer.Sound >> > objects, so they stay at the same places in the array, but in a for

Re: Cython taking more time than regular Python

2016-09-19 Thread Peter Otten
Arshpreet Singh wrote: > Hope this is good place to ask question about Cython as well. > Following code of mine is taking 2.5 times more time than Native Python > code: > > %%cython > import numpy as np > a = np.array([]) > def large_sum2(int num_range): > np.append(a,[i for i in xrange(num_

Re: Using copyreg to pickle unpicklable oblects

2016-09-19 Thread Peter Otten
kerbingamer376 wrote: > Hi, [No need to start a new thread for this] > I have an object (pygame.mixer.Sound) and, to convert it to a picklable > format, I can run: > > sound_object.get_raw() > > and to turn that back into an object, I can run: > > sound_object = pygame.mixer.Sound(raw_data) >

Re: Using copyreg to pickle unpicklable oblects

2016-09-19 Thread Peter Otten
kerbingamer376 wrote: > On Monday, September 19, 2016 at 5:48:35 PM UTC+1, Peter Otten wrote: >> kerbingamer376 wrote: >> >> > Hi, >> >> [No need to start a new thread for this] >> >> > I have an object (pygame.mixer.Sound) and,

Re: Cython taking more time than regular Python

2016-09-20 Thread Peter Otten
Stefan Behnel wrote: > Peter Otten schrieb am 19.09.2016 um 14:55: >> In [7]: %%cython >> def omega(int n): >> cdef long i >> cdef long result = 0 >> for i in range(n): result += i >> return result >>...: >> >> In [8]:

Re: Cython taking more time than regular Python

2016-09-20 Thread Peter Otten
Christian Gollwitzer wrote: > Am 20.09.16 um 09:44 schrieb Peter Otten: >> Stefan Behnel wrote: >> >>> Peter Otten schrieb am 19.09.2016 um 14:55: >>>> In [7]: %%cython >>>> def omega(int n): >>>> cdef long i >>&

Re: I am newbie who can explain this code to me?

2016-09-20 Thread Peter Otten
38016226...@gmail.com wrote: > 在 2016年9月20日星期二 UTC-4上午8:17:13,BartC写道: >> On 20/09/2016 13:12, 38016226...@gmail.com wrote: >> d = {} >> keys = range(256) >> vals = map(chr, keys) >> map(operator.setitem, [d]*len(keys), keys, vals) >> > >> > It is from python library. What does

Re: get the sum of differences between integers in a list

2016-09-20 Thread Peter Otten
Daiyue Weng wrote: > Hi, I have a list numbers say, > > [1,2,3,4,6,8,9,10,11] > > First, I want to calculate the sum of the differences between the numbers > in the list. > Second, if a sequence of numbers having a difference of 1, put them in a > list, i.e. there are two such lists, > > [1,2,3

Re: Linear Time Tree Traversal Generator

2016-09-20 Thread Peter Otten
ROGER GRAYDON CHRISTMAN wrote: > I am trying to find a better (i.e. more efficient) way to implement a > generator that traverses a tree. > > The current model of the code (which is also used by a textbook I am > teaching from does this) > >def __iter__(node): > for x in iter(node._

Re: I am newbie who can explain this code to me?

2016-09-20 Thread Peter Otten
Nobody wrote: > On Tue, 20 Sep 2016 15:12:39 +0200, Peter Otten wrote: > >> because they don't build lists only to throw them away. > > The lists could have been avoided by using iterators, e.g. > > import itertools as it > keys = xrange(256) > vals

Re: Another å, ä, ö question

2016-09-20 Thread Peter Otten
Martin Schöön wrote: > Den 2016-09-19 skrev Christian Gollwitzer : >> Am 19.09.16 um 22:21 schrieb Martin Schöön: >>> I am studying some of these tutorials: >>> https://pythonprogramming.net/matplotlib-intro-tutorial/ >>> >>> I am recreating the code and I use my native Swedish for comments, >>> l

Re: csjark module

2016-09-21 Thread Peter Otten
bezen...@gmail.com wrote: > After setting up csjark (http://csjark.readthedocs.io/), I'm trying to > test on of my C header files which has following statements: > > typedef struct { >unsigned long X; >__int64 Y; > } abc; > > > If I'm changing __int64 to unsigned long I'm not getting th

Re: csjark module

2016-09-21 Thread Peter Otten
bezen...@gmail.com wrote: > On Wednesday, September 21, 2016 at 1:14:14 PM UTC+3, Peter Otten wrote: >> bezen...@gmail.com wrote: >> >> > After setting up csjark (http://csjark.readthedocs.io/), I'm trying to >> > test on of my C header files which has fo

Re: csjark module

2016-09-21 Thread Peter Otten
bezen...@gmail.com wrote: > On Wednesday, September 21, 2016 at 3:17:11 PM UTC+3, Peter Otten wrote: >> bezen...@gmail.com wrote: >> >> > On Wednesday, September 21, 2016 at 1:14:14 PM UTC+3, Peter Otten >> > wrote: >> >> bezen...@gmail.com wrote:

Re: get the sum of differences between integers in a list

2016-09-21 Thread Peter Otten
Daiyue Weng wrote: > Hi, first of all, let me rephase the problem. > > For an arbitrary list of integers (the integers in the list are not > necessary to be sequential), e.g. [1,2,3,6,8,9,10,11,13], > > if a set of consecutive integers having a difference of 1 between them, > put them in a list,

Re: get the sum of differences between integers in a list

2016-09-21 Thread Peter Otten
Peter Otten wrote: > This is not as efficient as it should be -- the gaps are calculated twice, > the check for the first and the last position is repeated on every > iteration lots of packing and unpacking... -- To address some of my own criticism: def lonely(triple): left, val

Re: csjark module

2016-09-21 Thread Peter Otten
bezen...@gmail.com wrote: > On Wednesday, September 21, 2016 at 5:15:38 PM UTC+3, Peter Otten wrote: >> bezen...@gmail.com wrote: >> >> > On Wednesday, September 21, 2016 at 3:17:11 PM UTC+3, Peter Otten >> > wrote: >> >> bezen...@gmail.com wrote: &g

Re: csjark module

2016-09-22 Thread Peter Otten
bezen...@gmail.com wrote: > On Thursday, September 22, 2016 at 5:51:43 AM UTC+3, beze...@gmail.com > wrote: >> On Wednesday, September 21, 2016 at 10:09:25 PM UTC+3, Peter Otten wrote: >> > bezen...@gmail.com wrote: >> > >> > > On Wednesday, September

Re: Another å, ä, ö question

2016-09-22 Thread Peter Otten
Martin Schöön wrote: > Den 2016-09-20 skrev Peter Otten <__pete...@web.de>: >> Martin Schöön wrote: >> >>> Den 2016-09-19 skrev Christian Gollwitzer : >>>> Am 19.09.16 um 22:21 schrieb Martin Schöön: >>>>> I am studying some of these tutori

Re: h(re) for help, import re - on NameError

2016-09-22 Thread Peter Otten
Veek M wrote: > Is there a way to use .pythonrc.py to provide a help function that > autoloads whatever module name is passed like so: By the way, the current help() already loads a module if you pass its name as a string: $ echo 'print("importing foo")' > foo.py $ python3 Python 3.4.3 (defaul

Re: get the sum of differences between integers in a list

2016-09-23 Thread Peter Otten
Daiyue Weng wrote: > i, I am new to the advanced python techniques, and by studying your code, > I understand that when calling grouped function with values[1, 2, 3, 6, 8, > 9, 10, 11, 13, 17, 19], > > tee(values, 3) generated 3 iterators shared values > > left contains [1, 2, 3, 6, 8, 9, 10, 11

Re: memory utilization blow up with dict structure

2016-09-23 Thread Peter Otten
Christian wrote: > Hi, > > I'm wondering why python blow up a dictionary structure so much. > > The ids and cat substructure could have 0..n entries but in the most cases > they are <= 10,t is limited by <= 6. > > Thanks for any advice to save memory. > Christian > > > Example: > > {'0a0f7a3

ANN: asciimatics v1.7.0

2016-09-24 Thread Peter Brittain
I am very pleased to announce asciimatics v1.7.0! This is a major update since the last announced version of the package. ## What is asciimatics? Asciimatics is a package to help people create full-screen text UIs (from interactive forms to complex text animations) on Linux, Windows and OSX.

Re: it looks strange

2016-09-27 Thread Peter Otten
cpx...@gmail.com wrote: li=[lambda :x for x in range(10)] res=li[0]() print res > 9 > > why? Look what happens if you look up x manually: >>> li = [lambda :x for x in range(10)] >>> x 9 So at this point x is 9 and a function written to return the value bound to the name x will

Re: How to make a copy of chained dicts effectively and nicely?

2016-09-27 Thread Peter Otten
Nagy László Zsolt wrote: > The result that I need should be a real dict, not just a ChainMap. (It > is because I have to mutate it.) > > d1 = {'a':1, 'b':2} > d2 = {'c':3, 'd':4} > d3 = {'e':5, 'f':6} > > #1. My first naive approach was: > > > from collections import ChainMap > d = {} > for ke

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Peter Otten
Peng Yu wrote: > Hi, In many other functional language, one can change the closure of a > function. Which are those languages, and how do they work? And is Python actually a "functional language"? > Is it possible in python? I'm not sure what you mean. Something like >>> def f(x): ... d

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Peter Otten
Lawrence D’Oliveiro wrote: > On Wednesday, September 28, 2016 at 3:35:58 AM UTC+13, Peter Otten wrote: >> is Python actually a "functional language"? > > Yes [snip] No. To replace the mostly irrelevant link with something addressing my question: <http://python

Re: Can this be easily done in Python?

2016-09-28 Thread Peter Pearson
On Tue, 27 Sep 2016 12:58:40 -0700 (PDT), TUA wrote: > Is the following possible in Python? > > Given how the line below works > > TransactionTerms = 'TransactionTerms' > > > have something like > > TransactionTerms = > > that sets the variable TransactionTerms to its own name as string > represe

Re: How to call this method from main method

2016-09-28 Thread Peter Pearson
On Tue, 27 Sep 2016 23:44:11 -0700 (PDT), prasanthk...@gmail.com wrote: [snip] > > if __name__ == '__main__': > > GenAccessToken("This_is_a_Test_QED_MAC_Key_Which_Needs_to_be_at_Least_32_Bytes_Long", > "default", "default", 6, >"g,m,a,s,c,p,d") > > When i am calling the abov

Re: Syncing up iterators with gaps

2016-09-28 Thread Peter Otten
Tim Chase wrote: > I've got several iterators sharing a common key in the same order and > would like to iterate over them in parallel, operating on all items > with the same key. I've simplified the data a bit here, but it would > be something like > > data1 = [ # key, data1 > (1, "one A"

Re: Expression can be simplified on list

2016-09-29 Thread Peter Otten
MRAB wrote: > What if an _exhausted_ iterator was falsey? Many would expect it = iter("abc") while it: print(next(it)) to work (i. e. no StopIteration) -- if it doesn't, what's the actual usecase? If it does work there must be some lookahead which not all iterators can provide in a meani

Re: pyicloud: TypeError: 'dict_values' object does not support indexing

2016-09-30 Thread Peter Otten
Adam Funk wrote: > I'm trying to use pyicloud in idle3 (installed by pip3 on Ubuntu). > > > > The basic stuff works, but access to photos (following the > instructions) fails: > > photos = api.photos.all for photo in photos: > print(photo.

Re: Counting words in a string??

2016-09-30 Thread Peter Pearson
On Fri, 30 Sep 2016 11:37:19 -0700 (PDT), Jake wrote: > Hi, I need a program which: > 1) Asks the user for a sentence of their choice (not including punctuation) > 2) Ask the user which word they would like to know is repeated > 3) Print out to the user how many times the word came up which they c

Re: ConfigParser: use newline in INI file

2016-10-02 Thread Peter Otten
Thorsten Kampe wrote: > * Ned Batchelder (Sat, 1 Oct 2016 17:41:28 -0700 (PDT)) >> If you want to have \n mean a newline in your config file, you can >> do the conversion after you read the value: >> >> >>> "a\\nb".decode("string-escape") >> 'a\nb' > > Interesting approach (although it

Re: Need help for the print() function with a better order

2016-10-02 Thread Peter Pearson
On Sat, 1 Oct 2016 18:12:29 -0700 (PDT), 38016226...@gmail.com wrote: > I am trying to print a simple decision tree for my homework. > The answer must keep in this format: > > Top 7,4,0.95 > career gain = 100 > 1.Management 2, 3, 0.9709505944546686 > 2.Service 5, 1, 0.6500224216483541 >

Re: python (scipy) TypeError

2016-10-03 Thread Peter Pearson
On Mon, 3 Oct 2016 09:14:23 -0700 (PDT), chrischris201...@gmail.com wrote: [snip] > > i try to follow some tutorial but i have that error : > > Traceback (most recent call last): > File "C:\Python27\test\test\earth.py", line 42, in > slope_array = np.ones_like(data_array) * nodataval > TypeE

Re: lxml ignore none in getchildren

2016-10-04 Thread Peter Otten
Sayth Renshaw wrote: > I am following John Shipmans example from > http://infohost.nmt.edu/~shipman/soft/pylxml/web/Element-getchildren.html > xml = ''' > ... ''' pen = etree.fromstring(xml) penContents = pen.getchildren() for content in penContents: > ... print "%-10s %

Re: static, class and instance methods (Reposting On Python-List Prohibited)

2016-10-06 Thread Peter Otten
ast wrote: > > "Lawrence D’Oliveiro" a écrit dans le message de > news:f5314bdd-a98f-4a16-b546-bd8efe4dd...@googlegroups.com... >> On Thursday, October 6, 2016 at 7:54:08 PM UTC+13, ast wrote: >>> But there is no decorator, why ? Is python doing the conversion >>> of funct2 to a descriptor itsel

Re: User Interface Suggestions? (newbie)

2016-10-06 Thread Peter Otten
BartC wrote: > On 05/10/2016 23:12, Akira Li wrote: >> Beverly Howard writes: >> >>> ...snip... >>> A primary question would be, "What are options for building a display >>> that would update displayed values without scrolling?" >> >> To rewrite only the last character, you could use '\b': >> >>

Re: A newbie doubt on methods/functions calling

2016-10-06 Thread Peter Otten
mr.puneet.go...@gmail.com wrote: > Hi > > I just started learning python. Is there any way to call functions in > different way ? > > Rather calling obj.function(arg1, arg2) I would like to call like below > > "obj function arg1 arg2" How would the machine reading the above know that you didn'

Re: Doubled backslashes in Windows paths

2016-10-07 Thread Peter Otten
Oz-in-DFW wrote: > I'm using Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC > v.1900 32 bit (Intel)] on Windows 7 > > I'm trying to write some file processing that looks at file size, > extensions, and several other things and I'm having trouble getting a > reliably usable path to

Re: define variables in the txt file using python

2016-10-08 Thread Peter Otten
Xristos Xristoou wrote: > hello > > > i have one .txt file and i want to create python script with sys.argv or > argparse or other package to define some variables in the txt file and i > take some result. > > > > txt file maybe like this : > > input number 1= %var1% > input number 2= %var2%

Re: define variables in the txt file using python

2016-10-08 Thread Peter Otten
Xristos Xristoou wrote: > Τη Σάββατο, 8 Οκτωβρίου 2016 - 12:25:28 π.μ. UTC+3, ο χρήστης Xristos > Xristoou έγραψε: >> hello >> >> >> i have one .txt file and i want to create python script with sys.argv or >> argparse or other package to define some variables in the txt file and i >> take some r

Re: while loop (Reposting On Python-List Prohibited)

2016-10-12 Thread Peter Otten
BartC wrote: > On 12/10/2016 05:30, Lawrence D’Oliveiro wrote: >> On Wednesday, October 12, 2016 at 11:23:48 AM UTC+13, BartC wrote: >>> while n>=x: >>> n=n-1 >>> print "*"* n >>> else: >>> print ("2nd loop exit n=",n,"x=",x) >> >> What is the difference between that and >> >> w

Re: try-except with no exceptions

2016-10-13 Thread Peter Otten
Daiyue Weng wrote: > Hi, I have seen code using try_except with no exceptions, > > from dateutil import parser > > try: > from_date = datetime.datetime.strptime(parameters['from_date'], > '%Y-%m-%d %H:%M:%S.%f') > to_date = datetime.datetime.strptime(parameters['to_date'], > '%Y-%m-%d %H

Re: Different behaviour of regexp in 3.6.0b2

2016-10-14 Thread Peter Otten
Lele Gaifax wrote: > Hi all, > > trying out pgcli with Python 3.6.0b2 I got an error related to what seem a > different behaviour, or even a bug, of re.sub(). > > The original intent is to replace spaces within a string with the regular > expression \s+ (see > https://github.com/dbcli/pgcli/blo

Re: Different behaviour of regexp in 3.6.0b2

2016-10-14 Thread Peter Otten
Lele Gaifax wrote: > Peter Otten <__pete...@web.de> writes: > >> Lele Gaifax wrote: >> >>> The original intent is to replace spaces within a string with the >>> regular expression \s+ (see >>> ... >>> Accordingly to the documenta

Re: How to sort this without 'cmp=' in python 3?

2016-10-15 Thread Peter Otten
38016226...@gmail.com wrote: > nums=['3','30','34','32','9','5'] > I need to sort the list in order to get the largest number string: > '953433230' > > nums.sort(cmp=lambda a,b: cmp(a+b, b+a), reverse=True) > > But how to do this in python 3? > > Thank you While cmp_to_key is neat doing it by

Re: Different behaviour of regexp in 3.6.0b2

2016-10-15 Thread Peter Otten
Serhiy Storchaka wrote: > On 14.10.16 20:01, Peter Otten wrote: >>>>> def double_bs(s): return "".join(s.split("\\")) >> ... > Just use s.replace('\\', r'\\'). D'oh! -- https://mail.python.org/mailman/listinfo/python-list

Re: How make the judge with for loop?

2016-10-16 Thread Peter Otten
38016226...@gmail.com wrote: > c="abcdefghijk" > len=len(c) > n is a int > sb=[[] for i in range(n)] > > while (i < len) { > for (int j = 0; j < n && i < len; j++) > sb[j].append(c[i++]); > for (int j = n-2; j >= 1 && i < len; j--) // > sb[j].append(c[i

Re: function call questions

2016-10-18 Thread Peter Otten
chenyong20...@gmail.com wrote: > Hi, > I got a function call as this: > def add_to_tree(root,value_string): > ...print "root is %s, value_string is %s" % (root, value_string) > ...for ch in value_string: > ... print "ch is %s" % ch > ... root = root.setdefault(ch,{}) > ...

Re: function call questions

2016-10-18 Thread Peter Otten
chenyong20...@gmail.com wrote: >> > My question is: >> > (1) why root is always {}? >> >> Because that's what you bind it to in the line >> >> > ... root = root.setdefault(ch,{}) >> >> See >> for a description of the the s

Re: function call questions

2016-10-19 Thread Peter Otten
chenyong20...@gmail.com wrote: > 在 2016年10月19日星期三 UTC+8上午11:46:28,MRAB写道: >> On 2016-10-19 03:15, chenyong20...@gmail.com wrote: >> > Thanks Peter and Anssi for your kind help. Now I'm ok with the first >> > question. But the second question still confused me. Wh

Re: Inplace shuffle function returns none

2016-10-19 Thread Peter Otten
Steve D'Aprano wrote: > On Wed, 19 Oct 2016 07:25 am, Sayth Renshaw wrote: > >> So why can't i assign the result slice to a variable b? >> >> It just keeps getting none. > > Of course you can assign the result slice to b. You just have to do it the > right way. > > You keep getting None becaus

Re: Converting the keys of a dictionary from numeric to string

2016-10-20 Thread Peter Otten
pozz wrote: > I have a dictionary where the keys are numbers: > > mydict = { 1: 1000, 2: 1500, 3: 100 } > > I would like to convert keys from number to string representation: > > mydict = { "apples": 1000, "nuts": 1500, "tables": 100 } > > Of course, somewhere I have the association between ke

Re: Converting the keys of a dictionary from numeric to string

2016-10-20 Thread Peter Otten
Paul Rubin wrote: > Peter Otten <__pete...@web.de> writes: >> assert len(keydict) == len(mydict) > > assert set(keydict) == set(mydict) The weaker check is O(1), and, combined with the succeeding for loop, implies the above. -- https://mail.python.org/mailman/listinfo/python-list

Re: Converting the keys of a dictionary from numeric to string

2016-10-20 Thread Peter Otten
Peter Otten wrote: > Paul Rubin wrote: > >> Peter Otten <__pete...@web.de> writes: >>> assert len(keydict) == len(mydict) >> >> assert set(keydict) == set(mydict) > > The weaker check is O(1), and, combined with the succeeding for loop, > imp

Re: tkinter callbacks stop working

2016-10-21 Thread Peter Otten
namenobodywa...@gmail.com wrote: > hello pythonistas > > the script below plays tictactoe; everything works; but if i replace the > block at the bottom > > if True: > > > with this instead > > def function(): Below I use main() instead. > > function() > > then the tkinter callback

Re: MySQL connector issue

2016-10-23 Thread Peter Otten
Joseph L. Casale wrote: > I have some code that I am testing on Windows without c extensions which > runs on a RHEL server with c extensions. In a simplified test case as > follows: > > connection = mysql.connector.connect(...) > cursor = connection.cursor(cursor_class=MySQLCursorDict) > while Tr

Re: retain dimensions for numpy slice

2016-10-24 Thread Peter Otten
duncan smith wrote: > Hello, > I have several arrays that I need to combine elementwise in > various fashions. They are basically probability tables and there is a > mapping of axes to variables. I have code for transposing and reshaping > that aligns the variables / axes so the usual broadc

Re: Reversing \N{...} notation?

2016-10-25 Thread Peter Otten
Tim Chase wrote: > I like the clarity of using the "\N{...}" notation when creating > string literals involving Unicode chars. > > Is there a built-in way to get such strings back from Python? > > >>> s = 'ma\N{LATIN SMALL LETTER N WITH TILDE}ana' > >>> s > 'mañana' > >>> magic(s) > 'ma\\N{

Re: lxml and xpath(?)

2016-10-26 Thread Peter Otten
Doug OLeary wrote: > Hey; > > Reasonably new to python and incredibly new to xml much less trying to > parse it. I need to identify cluster nodes from a series of weblogic xml > configuration files. I've figured out how to get 75% of them; now, I'm > going after the edge case and I'm unsure how t

Re: Reversing \N{...} notation?

2016-10-26 Thread Peter Otten
Tim Chase wrote: > On 2016-10-25 20:14, Peter Otten wrote: >> Tim Chase wrote: >> > I like the clarity of using the "\N{...}" notation when creating >> > string literals involving Unicode chars. >> > >> > Is there a built-in way to get su

Re: lxml and xpath(?)

2016-10-27 Thread Peter Otten
Pete Forman wrote: > Peter Otten <__pete...@web.de> writes: > >> root = etree.fromstring(s) >> for server in root.xpath("./server"): >> servername = server.xpath("./name/text()")[0] > > When working with lxml I prefer to use this P

Re: Windows switch between python 2 and 3

2016-10-27 Thread Peter Otten
Daiyue Weng wrote: > Hi, I installed Python 2.7 and Python 3.5 64 bit versions on Win 10. Under > > C:\Python35 > > C:\Python27 > > Both have been set in environment variable Path. > > When I type python in cmd, it only gives me python 2.7, I am wondering how > to switch between 2 and 3 in com

Re: __prepare__ metaclass's method

2016-10-28 Thread Peter Otten
ast wrote: > Hi > > On python doc here: > > https://docs.python.org/3.4/reference/datamodel.html > > it is said about __prepare__ metaclass's method: > > If the metaclass has a __prepare__ attribute, it is called as > namespace = metaclass.__prepare__(name, bases, **kwds) > where the additiona

Re: Calling Bash Command From Python

2016-10-31 Thread Peter Otten
Wildman via Python-list wrote: > Python 2.7.9 on Linux > > Here is a bash command that I want to run from a python > program: sudo grep "^user\:" /etc/shadow > > If I enter the command directly into a terminal it works > perfectly. If I run it from a python program it returns an > empty string

Re: Announcement: PythonQL - An integrated query language for Python

2016-11-01 Thread Peter Otten
Pavel Velikhov wrote: > We have released PythonQL, a query language extension to Python (we have > extended Python’s comprehensions with a full-fledged query language, > drawing from the useful features of SQL, XQuery and JSONiq). Take a look > at the project here: http://www.pythonql.org and le

Re: Announcement: PythonQL - An integrated query language for Python

2016-11-01 Thread Peter Otten
Pavel Velikhov wrote: > On Tuesday, 1 November 2016 12:50:37 UTC+3, Peter Otten wrote: >> Pavel Velikhov wrote: >> >> > We have released PythonQL, a query language extension to Python (we >> > have extended Python’s comprehensions with a full-fledged query

Re: Force virtualenv pip to be used

2016-11-06 Thread Peter Otten
.4 from /usr/lib/python2.7/dist-packages (python 2.7) (a)$ unset PYTHONPATH (a)$ pip --version pip 1.5.4 from /home/peter/a/local/lib/python2.7/site-packages (python 2.7) -- https://mail.python.org/mailman/listinfo/python-list

Re: Force virtualenv pip to be used

2016-11-06 Thread Peter Otten
Chris Angelico wrote: > On Sun, Nov 6, 2016 at 9:17 PM, Alec Taylor > wrote: >> Running Ubuntu 16.10 with Python 2.7.12+ (default one) and virtualenv >> 15.0.3 (`sudo -H pip install virtualenv`). What am I doing wrong? >> >> $ virtualenv a && . "$_"/bin/activate && pip --version > > I'm pret

Re: Force virtualenv pip to be used

2016-11-06 Thread Peter Otten
Alec Taylor wrote: > On Sunday, November 6, 2016 at 10:20:53 PM UTC+11, Peter Otten wrote: >> Chris Angelico wrote: >> >> > On Sun, Nov 6, 2016 at 9:17 PM, Alec Taylor >> > wrote: >> >> Running Ubuntu 16.10 with Python 2.7.12+ (default one) and

Re: N-grams

2016-11-10 Thread Peter Otten
srinivas devaki wrote: Interesting approach. > def myngrams(iterable, n=2): > t = list(tee(iterable, 1)) I don't think I've seen tee(iterable, 1) before. Did you do this for aesthetic reasons or is there an advantage over t = [iter(iterable)] ? > for _ in range(n - 1): >

Re: N-grams

2016-11-10 Thread Peter Otten
Paul Rubin wrote: > This can probably be cleaned up some: > > from itertools import islice > from collections import deque > > def ngram(n, seq): > it = iter(seq) > d = deque(islice(it, n)) > if len(d) != n: > return > for s in it: >

Re: update certain key-value pairs of a dict from another dict

2016-11-11 Thread Peter Otten
Tim Chase wrote: > On 2016-11-11 11:17, Daiyue Weng wrote: >> dict1 = {'A': 'a', 'B': 'b', 'C': 'c'} >> dict2 = {'A': 'aa', 'B': 'bb', 'C': 'cc'} >> >> I am wondering how to update dict1 using dict2 that >> >> only keys 'A' and 'B' of dict1 are udpated. It will result in >> >> dict1 = {'A': 'aa

Re: Printing a generator returns "", need to print its values

2016-11-16 Thread Peter Otten
vmaha...@centerpointmedia.com wrote: > I am running Python2.7, wherein I am running the following price of code: > > y = m.predict(input_fn=lambda:input_fn(df_predict), as_iterable=True) > print ('Predictions: {}'.format(str(y))) > > The output of the following is "" 0x7f0476373e10>" > > Howeve

Re: How to test for type or instance of dict_values?

2016-11-17 Thread Peter Otten
Thorsten Kampe wrote: > How can I test for type or instance of dictviews like dict_values? Why do you want to? > `isinstance({}.values, dict_values)` gives > `NameError: name 'dict_values' is not defined` You can "fix" this with >>> dict_values = type({}.values()) or, depending on the use ca

Re: Overlapping co-ordiantes of rectangles fail to print in python

2016-11-17 Thread Peter Pearson
On Thu, 17 Nov 2016 06:27:49 -0800 (PST), aruns...@gmail.com wrote: > I am working with following code in which I am trying to output co > ordinates of overlapping rectangles.. However the code fails to > output the co ordinates. I am customizing the following code [about 100 lines of code remo

Re: Style().configure don't works for all widgets

2016-11-18 Thread Peter Otten
Luis Marzulli wrote: > ttk.Style().configure(".", font=('Courier New', 30, "bold")) > > works for Button and Label widgets (and maybe others) and don't works for > Entry widget? > > Example in Python 3: > from tkinter import * > from tkinter import ttk > from tkinter import font > > root = Tk()

Re: Parsing a single-level JSON file

2016-11-18 Thread Peter Otten
mike.rei...@gmail.com wrote: > hi all, > > Im reading in a JSON file that looks like this > > > [ >{ > "name":"myField1", > "searchable":true, > "navigable":true, > "custom":true, > "clauseNames":[ > "cf[10190]", > "Log Details" > ],

Re: need help to get my python image to move around using tkinter

2016-11-18 Thread Peter Otten
twgrops--- via Python-list wrote: > Hi I am new here and to python, > > I am currently studying towards my degree in computer science and have to > build a program but I have hit a brick wall. I am trying to make an image > move around the canvas. I can make a rectangle move using the following:

Re: How to append a modified list into a list?

2016-11-19 Thread Peter Otten
jf...@ms4.hinet.net wrote: > I have a working list 'tbl' and recording list 'm'. I want to append 'tbl' > into 'm' each time when the 'tbl' was modified. I will record the change > by append it through the function 'apl'. > > For example: > tbl=[0,0] m=[] > tbl[0]=1 apl(tbl) >>>

<    7   8   9   10   11   12   13   14   15   16   >