Re: genfromtxt and comment identifier

2011-04-15 Thread Peter Otten
simona bellavista wrote: > Hi All, > > I have a problem with reading data from a file using genfromtxt of > numpy module. > > I have prepared a minimal example similar to the ones presented in > > http://docs.scipy.org/doc/numpy/user/basics.io.genfromtxt.html#splitting- the-lines-into-columns >

Re: optparse eats $

2011-04-19 Thread Peter Otten
tazz_ben wrote: > So, I'm using optparse as follows: > > Command line: > python expense.py ">$100" -f ~/desktop/test.txt > ['>00'] > > > In Main: > > desc = '' > p = optparse.OptionParser(description=desc) > > utilities = optparse.OptionGroup(p, 'Utility Options') > utilities.add_option('--fi

Re: Pairwise count of frequency from an incidence matrix of group membership

2011-04-20 Thread Peter Otten
Shafique, M. (UNU-MERIT) wrote: > Hi, > I have a number of different groups g1, g2, … g100 in my data. Each group > is comprised of a known but different set of members from the population > m1, m2, …m1000. The data has been organized in an incidence matrix: > g1g2g3g4g5 > m01 > m210010 > m301

Re: List comprehension vs filter()

2011-04-20 Thread Peter Otten
Chris Angelico wrote: > Context: Embedded Python interpreter, version 2.6.6 > > I have a list of dictionaries, where each dictionary has a "type" > element which is a string. I want to reduce the list to just the > dictionaries which have the same "type" as the first one. > > lst=[{"type":"calc"

Re: py32 on windows - input() includes trailing \r

2011-04-20 Thread Peter Otten
Frank Millman wrote: > On linux, python 3.2 - > x = input() > xyz len(x) > 3 x > 'xyz' > > on windows, python 3.2 - > x = input() > xyz len(x) > 4 x > 'xyz\r' > > Is this expected behaviour? No, that's a bug: http://bugs.python.org/issue11272 IMO it's severe e

Re: dictionary size changed during iteration

2011-04-20 Thread Peter Otten
Laszlo Nagy wrote: > Given this iterator: > > class SomeIterableObject(object): > > > > def __iter__(self): > ukeys = self.updates.keys() > for key in ukeys: > if self.updates.has_key(key): > yield self.updates[key] >

Re: dictionary size changed during iteration

2011-04-20 Thread Peter Otten
Peter Otten wrote: > Laszlo Nagy wrote: > >> Given this iterator: >> >> class SomeIterableObject(object): >> >> >> >> def __iter__(self): >> ukeys = self.updates.keys() >> for key in ukeys:

Re: is there a difference between one line and many lines

2011-04-21 Thread Peter Otten
vino19 wrote: > Hello, I'm a newbie. > What's the defference between > a=-6; b=-6; a is b True > > and > a=-6 b=-6 a is b False > > ? When you write it as a single line the assignments to a and b are part of the same compilation process, and as an optimization CPython

Re: is there a difference between one line and many lines

2011-04-21 Thread Peter Otten
Steven D'Aprano wrote: > but: > a = 1001; b = 10001; a is b > False I would hope so ;) > The point is that Python is free to re-use immutable objects, or not re- > use them, as it sees fit. Indeed, and I even found a Python implementation on my harddisk that does what you intended to sh

Re: suggestions, comments on an "is_subdict" test

2011-04-22 Thread Peter Otten
Vlastimil Brom wrote: > Hi all, > I'd like to ask for comments or advice on a simple code for testing a > "subdict", i.e. check whether all items of a given dictionary are > present in a reference dictionary. > Sofar I have: > > def is_subdict(test_dct, base_dct): > """Test whether all the it

Re: suggestions, comments on an "is_subdict" test

2011-04-22 Thread Peter Otten
Zero Piraeus wrote: > : > >>> I'd like to ask for comments or advice on a simple code for testing a >>> "subdict", i.e. check whether all items of a given dictionary are >>> present in a reference dictionary. > > Anything wrong with this? > > def is_subdict(test_dct, base_dct): > return tes

Re: suggestions, comments on an "is_subdict" test

2011-04-22 Thread Peter Otten
Zero Piraeus wrote: >>> Anything wrong with this? >>> >>> def is_subdict(test_dct, base_dct): >>> return test_dct <= base_dct and all(test_dct[k] == base_dct[k] for >>> k in test_dct) >> >> It may raise a KeyError. > > Really? That was what ``test_dct <= base_dct and`` ... is supposed to > preven

Re: dict comparison [was: suggestions, comments on an "is_subdict" test]

2011-04-22 Thread Peter Otten
Zero Piraeus wrote: > : > > On 22 April 2011 13:30, Peter Otten <__pete...@web.de> wrote: >>>>> def is_subdict(test_dct, base_dct): >> ... return test_dct <= base_dct and all(test_dct[k] == base_dct[k] >> for ... k in test_dct) >> ... >&

Re: unpickling derived LogRecord in python 2.7 from python2.6

2011-04-27 Thread Peter Otten
ivdn...@gmail.com wrote: > I have a service that runs in python 2.6.4. This service sends > LogRecords to a log monitoring app on my workstation running python > 2.7. The LogRecord class is derived: > > class LogRecord(logging.LogRecord): > > def __init__(self, name, level, fn, lno, user, ho

Re: unpickling derived LogRecord in python 2.7 from python2.6

2011-04-28 Thread Peter Otten
Vinay Sajip wrote: > On Apr 27, 5:41 pm, Peter Otten <__pete...@web.de> wrote: > >> The Problem is that as of Python 2.7logging.LogRecord has become a >> newstyle class which is pickled/unpickled differently. I don't know if >> there is an official way to do t

Re: argparse parser stores lists instead of strings

2011-04-28 Thread Peter Otten
Andrew Berg wrote: > I've set up groups of arguments for a script I'm writing, and any time I > give an argument a value, it gets stored as a list instead of a string, > even if I explicitly tell it to store a string. Arguments declared with > other types (e.g. float, int) and default values are s

Re: Spurious character in IOError exception

2011-04-28 Thread Peter Otten
loial wrote: > When I correctly trap an IOError a spurious u' appears in the file > path in the exception message : > > The path used in the code is correct i.e. /home/myfile > > But the error message says : > > [Errno 2] No such file or directory: u'/home/myfile' > > > I am simply doing > >

Re: (beginner) logging config not working

2011-04-29 Thread Peter Otten
Unknown Moss wrote: > Hi > > This is a beginner question. Thanks for the hand. > > I've been asked to maintain some poorly constructed python code. > Logging is weak. Getting it to work with python logging > programmatically was easy. > > However, I'd like to refactor all the logging code into

Re: Fibonacci series recursion error

2011-04-29 Thread Peter Otten
harrismh777 wrote: > def fib(i=1): > a=1;n=1;l=[] > for j in range(0,i): > l.append(a) > p=a;a=n;n=p+a Hm, did you run out of newlines? > return l > > list=fib(7) > > > > ... and the above, is how I would actually code it > > > > Nah, that can't be i

Re: Fibonacci series recursion error

2011-04-29 Thread Peter Otten
harrismh777 wrote: > Ian Kelly wrote: >> since the fact is that if >> the function were properly coded, the call stack for fib(20) would >> never be more than 20 entries deep at any one time. >> > > Not so much... and much more ! > > > ... because each recursion level 'return' calls fib()

Re: how to do random / SystemRandom switch

2011-04-30 Thread Peter Otten
Matthias Kievernagel wrote: > In my top-level script I want to select if my program > is to use random.xxx functions or the random.SystemRandom.xxx > ones. All the other modules shouldn't know about that > switch and simply use > import random > ... > return random.randint(1, 6) > ... > for exampl

Re: Fibonacci series recursion error

2011-04-30 Thread Peter Otten
harrismh777 wrote: > Peter Otten wrote: >> For the record, the one true way to implement the Fibonacci series in >> Python is >> >>>>> >>> def fib(): >> ... a = b = 1 >> ... while True: >> ... yield a &g

Re: codec for UTF-8 with BOM

2011-05-02 Thread Peter Otten
Ulrich Eckhardt wrote: > Chris Rebert wrote: >>> 3. The docs mention encodings.utf_8_sig, available since 2.5, but I >>> can't locate that thing there either. What's going on here? >> >> Works for me™: >> Python 2.6.6 (r266:84292, Jan 12 2011, 13:35:00) >> [GCC 4.2.1 (Apple Inc. build 5664)] on d

Re: Pickling extension types

2011-05-03 Thread Peter Otten
Stefan Kuzminski wrote: > I have an extension type written in C, but I cannot get it to pickle, any > insights would be greatly appreciated. > > I see in the docs that I should define a __reduce__ method and that does > get called, but I don't know specifically the type of the 'callable > object'

Re: Regular Expression for words (with umlauts, without numbers)

2011-05-13 Thread Peter Otten
Jens Lechtenboerger wrote: > I'm looking for a regular expression to recognize natural language > words with umlauts but without numbers. While \w with re.U does > recognize words with umlauts, it also matches numbers, which I do > not want. > > Is there a better way than an exhaustive enumerati

Re: Converting a set into list

2011-05-14 Thread Peter Otten
TheSaint wrote: > I've stumble to find a solution to get a list from a set > > > aa= ['a','b','c','f'] aa > ['a', 'b', 'c', 'f'] set(aa) To clarify: this creates a new object, so aa is still a list. > {'a', 'c', 'b', 'f'} [k for k in aa] > ['a', 'b', 'c', 'f'] So you are

Re: Converting a set into list

2011-05-15 Thread Peter Otten
Daniel Kluev wrote: >> Both solutions seem to be equivalent in that concerns the number of >> needed loop runs, but this two-step operation might require one less loop >> over list1. The set&set solution, in contrary, might require one loop >> while transforming to a set and another one for the &

Re: Convert AWK regex to Python

2011-05-16 Thread Peter Otten
J wrote: > Good morning all, > Wondering if you could please help me with the following query:- > I have just started learning Python last weekend after a colleague of mine > showed me how to dramatically cut the time a Bash script takes to execute > by re-writing it in Python. I was amazed at ho

Re: Convert AWK regex to Python

2011-05-16 Thread Peter Otten
J wrote: > Hello Peter, Angelico, > > Ok lets see, My aim is to filter out several fields from a log file and > write them to a new log file. The current log file, as I mentioned > previously, has thousands of lines like this:- 2011-05-16 09:46:22,361 > [Thr

Re: groupby - summing multiple columns in a list of lists

2011-05-17 Thread Peter Otten
Jackson wrote: > I'm currently using a function pasted in below. This allows me to sum > a column (index) in a list of lists. > > So if mylist = [[1, 2, 3], [1, 3, 4], [2, 3, 4], [2, 4, 5]] > group_results(mylist,[0],1) > > Returns: > [(1, 5), (2, 7)] > > What I would like to do is allow a tupl

Re: English Idiom in Unix: Directory Recursively

2011-05-18 Thread Peter Moylan
people call "iteration". This might be the first time I have ever found a point of agreement with Xah Lee. -- Peter Moylan, Newcastle, NSW, Australia. http://www.pmoylan.org For an e-mail address, see my web page. -- http://mail.python.org/mailman/listinfo/python-list

Re: English Idiom in Unix: Directory Recursively

2011-05-18 Thread Peter Moylan
; > Recursion: (N). See recursion. It's interesting to note that the definitions of 'recursive' to be found in Wikipedia and Wiktionary have very little in common with the definitions to be found in the dictionaries covered by Onelook. No wonder experts in different areas have trouble

Re: English Idiom in Unix: Directory Recursively

2011-05-18 Thread Peter Moylan
rusi wrote: > On May 18, 5:09 pm, Peter Moylan > wrote: >> ObAUE: In common parlance, the English word "recursion" means pretty >> much the same as what computing people call "iteration". This might be >> the first time I have ever found a point of a

Re: hash values and equality

2011-05-19 Thread Peter Otten
Ethan Furman wrote: > Several folk have said that objects that compare equal must hash equal, > and the docs also state this > http://docs.python.org/dev/reference/datamodel.html#object.__hash__ > > I'm hoping somebody can tell me what horrible thing will happen if this > isn't the case? Here's

Re: hash values and equality

2011-05-20 Thread Peter Otten
Ethan Furman wrote: > Peter Otten wrote: >> Ethan Furman wrote: >> >>> Several folk have said that objects that compare equal must hash equal, >>> and the docs also state this >>> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ &g

Re: TK program problem

2011-05-21 Thread Peter Otten
bvdp wrote: > I've just done an update to my system here to Ubuntu 11.04. Mostly no > problems ... but I have an important (to me) python/TK program that's > stopped working. Well, it works ... mostly. > > The python version is 2.7.1+ (no idea what the + means!). > > I _think_ I have traced the

Re: hash values and equality

2011-05-21 Thread Peter Otten
Gregory Ewing wrote: > Ethan Furman wrote: >> Ulrich Eckhardt wrote: >> >>> If two equal objects have different hashes, they >>> will be stored in different places in the hash map. Looking for >>> object1 will then not turn up with object2, even though they are equal. >> >> In this case this is

Re: count strangeness

2011-05-21 Thread Peter Otten
James Stroud wrote: > tal 65% python2.7 > Python 2.7.1 (r271:86832, May 21 2011, 22:52:14) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > py> class C(object): > ... def __init__(self): > ... self.data = [] >

Re: count strangeness

2011-05-22 Thread Peter Otten
James Stroud wrote: > Peter Otten wrote: >> James Stroud wrote: >>> WTF? >> >> Put the code into a file, run it -- and be enlightened ;) > > > tal 72% python2.7 eraseme.py > 1 > 2 > 4 > 8tal 73% cat eraseme.py > #! /usr/bin/env python &

Re: Code Review

2011-05-25 Thread Peter Otten
ad wrote: > Please review the code pasted below. I am wondering what other ways > there are of performing the same tasks. This was typed using version > 3.2. The script is designed to clean up a directory (FTP, Logs, etc.) > Basically you pass two arguments. The first argument is an number of > da

Re: changing current dir and executing a shell script

2011-05-28 Thread Peter Otten
Albert Hopkins wrote: > On Fri, 2011-05-27 at 14:25 -0700, suresh wrote: >> I want to execute the following command line stuff from inside python. >> $cd directory >> $./executable >> >> I tried the following but I get errors >> import subprocess >> subprocess.check_call('cd dir_name;./executabl

Re: GIL in alternative implementations

2011-05-28 Thread Peter Otten
Daniel Kluev wrote: >> So I'd like to know: how do these other implementations handle >> concurrency matters for their primitive types, and prevent them from >> getting corrupted in multithreaded programs (if they do) ? I'm not only >> thinking about python types, but also primitive containers and

Re: scope of function parameters

2011-05-29 Thread Peter Pearson
On Sun, 29 May 2011 04:30:52 -0400, Henry Olders wrote: [snip] > def main(): > a = ['a list','with','three elements'] > print a > print fnc1(a) > print a > > def fnc1(b): > return fnc2(b) > > def fnc2(c): > c[1] = 'having' > return c > > This is the

Re: scope of function parameters

2011-05-30 Thread Peter Otten
Laurent Claessens wrote: > Le 30/05/2011 11:02, Terry Reedy a écrit : >> On 5/30/2011 3:38 AM, Laurent wrote: >> >>> Cool. I was thinking that "5" was the name, but >>> >>> 5.__add__(6) >>> File "", line 1 >>> 5.__add__(6) >> >> >> Try 5 .__add__(6) > > What is the rationale behind the fact

Re: Best way to compute length of arbitrary dimension vector?

2011-05-30 Thread Peter Otten
Gabriel wrote: > Well, the subject says it almost all: I'd like to write a small Vector > class for arbitrary-dimensional vectors. > > I am wondering what would be the most efficient and/or most elegant > way to compute the length of such a Vector? > > Right now, I've got > > def length(self)

Re: English Idiom in Unix: Directory Recursively

2011-05-30 Thread Peter Moylan
rantingrick wrote: > On May 18, 7:19 am, Peter Moylan > wrote: > >> It's interesting to note that the definitions of 'recursive' to be found >> in Wikipedia and Wiktionary have very little in common with the >> definitions to be found in the dictionaries

Re: English Idiom in Unix: Directory Recursively

2011-05-30 Thread Peter Moylan
ng of "share" has contributed anything of value to the language. Which is possibly why people stopped using it in about the 1980s. -- Peter Moylan, Newcastle, NSW, Australia. http://www.pmoylan.org For an e-mail address, see my web page. -- http://mail.python.org/mailman/listinfo/python-list

Re: Have do_nothing as default action for dictionary?

2017-09-03 Thread Peter Otten
Christopher Reimer via Python-list wrote: > Greetings, > > I was playing around this piece of example code (written from memory). > > > def filter_text(key, value): > > def do_nothing(text): return text > > return {'this': call_this, > > 'that': call_that, > > 'what': do_nothing > > }

Re: Have do_nothing as default action for dictionary?

2017-09-03 Thread Peter Otten
Christopher Reimer via Python-list wrote: > Greetings, > > I was playing around this piece of example code (written from memory). > > > def filter_text(key, value): > > def do_nothing(text): return text > > return {'this': call_this, > > 'that': call_that, > > 'what': do_nothing > > }

Re: XML Parsing

2017-09-04 Thread Peter Otten
Sambit Samal wrote: > Hi , > > Need help in Python Script using xml.etree.ElementTree to update the > value of any element in below XML ( e.g SETNPI to be 5 ) based on some > constraint ( e.g ) . Something along the lines from xml.etree import ElementTree as ET tree = ET.parse("original.xml"

Re: How do I find what kind of exception is thrown.

2017-09-05 Thread Peter Otten
Antoon Pardon wrote: > Python 2.6.4 on a solaris box. > > I have a program in which all kind of excptions can be thrown and caugth. > The main program is something like below: > > try: > do_stuff > except Exception: > log unexpected trouble > > Now I found the following in the logs: [Er

Re: execfile and import not working

2017-09-06 Thread Peter Otten
Friedrich Rentsch wrote: > Hi, I am setting up Python 2.7 after an upgrade to Ubuntu 16.04, a > thorough one, leaving no survivors. Everything is fine, IDLE opens, > ready to go. Alas, execfile and import commands don't do my bidding, but > hang IDLE. All I can do is kill the process named "python

Re: cant't use package internals

2017-09-06 Thread Peter Otten
Andrej Viktorovich wrote: > Hello, > > I have Python package tst in my workspace. > > tst has files: > __init__.py > tst.py > > > content of __init__.py: > print("importing Tst") > > > content of tst.py: > class Tst: > def __init__(self): > print("init Tst") > > > I run python

Re: execfile and import not working

2017-09-06 Thread Peter Otten
Friedrich Rentsch wrote: > > > On 06.09.2017 10:52, Peter Otten wrote: >> Friedrich Rentsch wrote: >> >>> Hi, I am setting up Python 2.7 after an upgrade to Ubuntu 16.04, a >>> thorough one, leaving no survivors. Everything is fine, IDLE opens, >

Re: Need to pass a class instance to a gettext fallback

2017-09-07 Thread Peter Otten
Josef Meile wrote: > Hi > > I'm working with gettext and need to define a language Fallback. I got > this working, but with a global variable. I don't really like this and I > would like to pass this variable to the gettext Fallback's contructor, but > I don't know how. For simplicity, I won't pu

Re: Design: method in class or general function?

2017-09-08 Thread Peter Otten
leam hall wrote: > On Thu, Sep 7, 2017 at 8:16 AM, Steve D'Aprano > wrote: > >> On Thu, 7 Sep 2017 07:20 pm, Leam Hall wrote: >> >> > OOP newbie on Python 2.6. >> >> Python 2.6 is ancient, and is missing many nice features. You should >> consider >> using the latest version, 3.6. >> > > I've wr

RE: Need to pass a class instance to a gettext fallback

2017-09-08 Thread Peter Otten
Josef Meile wrote: > language = kwargs['language'] > del kwargs['language'] Not really important, but there's a method for that: language = kwargs.pop("language") > def __init__(self, *args, **kwargs): > language = kwargs['language'] > del kwargs['language'] In Python 3 this can also

Re: detaching comprehensions

2017-09-08 Thread Peter Otten
Stefan Ram wrote: > Maybe you all know this, but to me this is something new. > I learnt it by trial and error in the Python 3.6.0 console. > > Most will know list comprehensions: > > |>>> [ i for i in range( 3, 5 )] > |[3, 4] > > I found out that the comprehension can be detached from

Re: Hat difference between "" and '' in string definition

2017-09-09 Thread Peter Otten
Andrej Viktorovich wrote: > What is difference between string definitions: > s="aaa" > and > s='bbb' There's no difference. It helps you avoid explicit escapes, i. e. >>> "What's up?" "What's up?" is a tad more readable than >>> 'What\'s up' "What's up" Likewise, multiline strings are easier

Re: Design: method in class or general function?

2017-09-11 Thread Peter Otten
Leam Hall wrote: > On 09/08/2017 03:06 AM, Peter Otten wrote: >> leam hall wrote: >> >>> On Thu, Sep 7, 2017 at 8:16 AM, Steve D'Aprano >>> wrote: >>> >>>> On Thu, 7 Sep 2017 07:20 pm, Leam Hall wrote: >>>> >>>&

Re: Design: method in class or general function?

2017-09-11 Thread Peter Otten
Leam Hall wrote: > I do not understand your last sentence about reference cycle. Currently you have - create Career instance which stores character as an attribute - make modifications to character - forget about Career instance My suggestion - create Career instance which stores character as

Re: Standard for dict-contants with duplicate keys?

2017-09-15 Thread Peter Otten
Tim Chase wrote: > Looking through docs, I was unable to tease out whether there's a > prescribed behavior for the results of defining a dictionary with the > same keys multiple times > > d = { > "a": 0, > "a": 1, > "a": 2, > } > > In my limited testing, it appears to alwa

Re: Which database system?

2017-09-16 Thread Peter Otten
Stefan Ram wrote: > Michael Torrie writes: >>On 09/15/2017 12:04 PM, Stefan Ram wrote: >>>writes some complex queries to the table, what can be expected >>^^ >>How do you plan to code these queries? > > I did a quick prototype. I am aware that the code >

Re: Unicode

2017-09-17 Thread Peter Otten
Leam Hall wrote: > On 09/17/2017 08:30 AM, Chris Angelico wrote: >> On Sun, Sep 17, 2017 at 9:38 PM, Leam Hall wrote: >>> Still trying to keep this Py2 and Py3 compatible. >>> >>> The Py2 error is: >>> UnicodeEncodeError: 'ascii' codec can't encode character >>> u'\xf6' in posit

Re: Unicode

2017-09-17 Thread Peter Otten
leam hall wrote: > Doesn't seem to work. The failing code takes the strings as is from the > database. it will occasionally fail when a name comes up that uses > a non-ascii character. Your problem in nuce: the Python 2 __str__() method must not return unicode. >>> class Character: ... def _

Re: How do I check all variables returned buy the functions exists

2017-09-20 Thread Peter Otten
Bill wrote: > Robin Becker wrote: >> On 16/09/2017 01:58, Steve D'Aprano wrote: >> >>> >>> If you want to test for None specifically: >>> >>> if any(v is None for v in values): >>> print "at least one value was None" >>> >> ... >> >> for some reason that seems slow on my machine

Re: Convert pandas series to string and datetime object

2017-09-21 Thread Peter Otten
zljubi...@gmail.com wrote: > I have sliced the pandas dataframe > > end_date = df[-1:]['end'] > > type(end_date) > Out[4]: pandas.core.series.Series > > end_date > Out[3]: > 48173 2017-09-20 04:47:59 > Name: end, dtype: datetime64[ns] > > 1.How to get rid of index value 48173 and get onl

Re: what is happening in panda "where" clause

2017-09-22 Thread Peter Otten
Exposito, Pedro (RIS-MDW) wrote: > This code does a "where" clause on a panda data frame... > > Code: > import pandas as pd; > col_names = ['Name', 'Age', 'Weight', "Education"]; > # create panda dataframe > x = pd.read_csv('test.dat', sep='|', header=None, names = col_names); > #

Re: Convert pandas series to string and datetime object

2017-09-22 Thread Peter Otten
Pavol Lisy wrote: > pandas is one of reasons why python is so popular these days. But > "there is only milion way how to do it" (and other unpythonic issues) > I see there every time I am looking at it. :) Yeah, such a useful tool with such a byzantine API, completely at odds with the zen -- I w

Re: search and replace first amount of strings instances with one thing and a second amount of instances with another thing-

2017-09-23 Thread Peter Otten
validationma...@gmail.com wrote: > i have a code in python to search and replace what i need though is to > replace the first say 10 instances of the number 1 with 2 and the second > 10 instances with the number 3. anybody knows how to do that? > > fin = open(r'F:\1\xxx.txt') > fout = open(r'F:\1

Re: search and replace first amount of strings instances with one thing and a second amount of instances with another thing-

2017-09-23 Thread Peter Otten
Peter Otten wrote: > validationma...@gmail.com wrote: > >> i have a code in python to search and replace what i need though is to >> replace the first say 10 instances of the number 1 with 2 and the second >> 10 instances with the number 3. anybody knows how to do that?

Re: Reference cycles

2017-09-24 Thread Peter Otten
Steve D'Aprano wrote: > Is there a way to log when the garbage collector finds and collects a > reference cycle? > > I don't care about objects claimed by the reference counter, I only care > about cycles. I don't know, and I don't think so. Would a structure like a --- b --- c | | | d

Re: TypeError with map with no len()

2017-09-25 Thread Peter Otten
john polo wrote: > Python List, > > I am trying to make practice data for plotting purposes. I am using > Python 3.6. The instructions I have are > > import matplotlib.pyplot as plt > import math > import numpy as np > t = np.arange(0, 2.5, 0.1) > y1 = map(math.sin, math.pi*t) > plt.plot(t,y1) >

Re: Running a GUI program haults the calling program (linux)

2017-09-26 Thread Peter Otten
Kryptxy via Python-list wrote: > Sent with [ProtonMail](https://protonmail.com) Secure Email. > >> Original Message >> Subject: Re: Running a GUI program haults the calling program (linux) >> Local Time: 26 September 2017 12:09 PM >> UTC Time: 26 September 2017 06:39 >> From: c.

Re: Finding keyword arguments in the documentation

2017-09-26 Thread Peter Otten
Stefan Ram wrote: > Here's a console transcript: > > |>>> from math import sin > |>>> help( sin ) > |Help on built-in function sin in module math: > | > |sin(...) > |sin(x) > | > |Return the sine of x (measured in radians). > | > |>>> sin( x = 2.0 ) > |Traceback (most recent call last):

Re: Finding keyword arguments in the documentation

2017-09-26 Thread Peter Otten
Jerry Hill wrote: > On Tue, Sep 26, 2017 at 12:32 PM, Peter Otten <__pete...@web.de> wrote: >> Newer Python versions will show >> >> Help on built-in function sin in module math: >> >> sin(x, /) >> Return the sine of x (measured in radians). >

Re: Newbie problem with urllib.request.urlopen

2017-09-26 Thread Peter Otten
Bernie Connors wrote: > On Tuesday, September 26, 2017 at 12:32:18 PM UTC-3, Bernie Connors wrote: >> Hello, >> >> My first post here on C.L.P. I have only written a few python >> scripts in 2.7 and now I'm trying my first python 3 script. Can >> you tell me why this snippet w

Re: Parentheses (as after "print")

2017-09-27 Thread Peter Otten
Stefan Ram wrote: > Why do we newbies write »print 2«? Here's another hint. > This is an original transcript of what happened to me today: > > |>>> import( operator ) > | File "", line 1 > |import( operator ) > | ^ > |SyntaxError: invalid syntax > | > |>>> import operator > | >

Re: Spacing conventions

2017-09-27 Thread Peter Otten
Bill wrote: > Ever since I download the MyCharm IDE a few days ago, I've been noticing > all sort of "spacing conventions (from PEP) that are suggested. How do > folks regard these in general? > > For instance, the conventions suggest that > > if x>y : > pass > > should be written > if

Re: Printing a Chunk Of Words

2017-09-27 Thread Peter Otten
Matt Wheeler wrote: > With deepest apologies to all involved... > > On Tue, 26 Sep 2017 at 08:42 Gregory Ewing > wrote: > >> Ben Bacarisse wrote: >> > Think functional! This is 257 characters: >> >> 250 chars, 17 shorter than the text it produces: >> >> a=[];o=[];n=[];A=list.append >> for b in

Re: Redirecting stdio streams with a context manager

2017-09-29 Thread Peter Otten
Steve D'Aprano wrote: > In the standard library's contextlib.py module, there is a class for > redirecting standard I/O streams, and two public functions. The code is > short enough to reproduce here: > > # From Python 3.5 > > class _RedirectStream: > _stream = None > def __init__(self,

Re: on a very slow function

2017-10-02 Thread Peter Otten
Daniel Bastos wrote: > def make_sequence_non_recursive(N, x0 = 2, c = -1): > "What's wrong with this function? It's very slow." > last = x0 > def sequence(): > nonlocal last > next = last > last = last**2 + c > return next % N > return sequence > > It crawls pretty soon.

Re: on a very slow function

2017-10-02 Thread Peter Otten
bartc wrote: > On 02/10/2017 08:41, Peter Otten wrote: >> Daniel Bastos wrote: >> >>> def make_sequence_non_recursive(N, x0 = 2, c = -1): >>>"What's wrong with this function? It's very slow." >>>last = x0 >>>de

Re: when is filter test applied?

2017-10-03 Thread Peter Otten
Neal Becker wrote: > In the following code (python3): > > for rb in filter (lambda b : b in some_seq, seq): > ... some code that might modify some_seq > > I'm assuming that the test 'b in some_seq' is applied late, at the start > of each iteration (but it doesn't seem to be working that way in

Re: The "loop and a half"

2017-10-03 Thread Peter Otten
Stefan Ram wrote: > Is this the best way to write a "loop and a half" in Python? > > x = 1 > while x: > x = int( input( "Number (enter 0 to terminate)? " )) > if x: > print( f'Square = { x**2 }' ) > > In a C-like language, one could write: > > while x = int( input( "Number (

Re: The "loop and a half"

2017-10-05 Thread Peter Otten
Stefan Ram wrote: > bartc writes: >>Note that your reverse-indentation style is confusing! > > In Python, indentation can be significant. > > Sometimes, some lines in Python must be indented by 0. Are there any editors that do not support a dedent operation? In the interactive interpreter

Re: Introducing the "for" loop

2017-10-05 Thread Peter Otten
Stefan Ram wrote: > "ROGER GRAYDON CHRISTMAN" writes: >>On Wed, Oct 4, 2017 22:42 Stefan Ram (r...@zedat.fu-berlin.de) wrote: >>Steve D'Aprano writes: So, "bottom-up" in this case means: iterators should be taught before for-loops. Why? >>The easy answer here is to not use the range

Re: How do native namespaces work?

2017-10-05 Thread Peter Otten
; > -- > $ cd sample-namespace-packages/native/pkg_a/ > $ python3 setup.py install Are you sure you are using the correct interpreter? When I activate a virtual environment it changes the prompt like so: $ python3 -m venv venv $ . venv/bin/

Re: How do native namespaces work?

2017-10-05 Thread Peter Otten
Thomas Nyberg wrote: > Hello, > > I'm trying to understand native namespaces. I'm currently using python > 3.5 as packaged in debian 9. I've been following the instructions here: > > https://packaging.python.org/guides/packaging-namespace-packages/#native-namespace-packages > > Those instructio

Re: why does memory consumption keep growing?

2017-10-06 Thread Peter Otten
Chris Angelico wrote: > On Fri, Oct 6, 2017 at 4:14 PM, Gregory Ewing > wrote: >> Steve D'Aprano wrote: >>> >>> Plus the downtime and labour needed to install the memory, if the >>> computer will even take it. >> >> >> Obviously we need an architecture that supports hot-swappable >> robot-install

Re: Is there a way to globally set the print function separator?

2017-10-09 Thread Peter Otten
John Black wrote: > I want sep="" to be the default without having to specify it every time I > call print. Is that possible? No, but you can replace the print function with your own: >>> print = functools.partial(print, sep="") >>> print("I", "recommend", "you", "choose", "another", "name", "a

Re: pathlib PurePosixPath

2017-10-10 Thread Peter Otten
Sayth Renshaw wrote: > Thanks. Updated the script. But shouldn't it create the file if it doesn't > exist? Which none of them will. > pathlib.PurePath(r'C:\Users\Sayth\Projects\results', file_name) > with open(result_path, 'a') as f: > f.write(data) > ##Output > File

Re: Introducing the "for" loop

2017-10-10 Thread Peter Otten
Stefan Ram wrote: > Which advice do you refer to? Teach the parts that are most useful first, i. e. for loops over anything but range rather than while loops. -- https://mail.python.org/mailman/listinfo/python-list

Re: Logging from files doesn't work

2017-10-12 Thread Peter Otten
Andrew Z wrote: > Hello, > > apparently my reading comprehension is nose diving these days. After > reading python cookbook and a few other tutorials i still can't get a > simple logging from a few files to work. > I suspected my file organization - all files are in the same directory, > causing

Re: unorderable types: list() > int()

2017-10-13 Thread Peter Otten
Andrew Z wrote: > Hello, > pos = {"CLown":10,"BArbie":20} > I want to return integer (10) for the keyword that starts with "CL" > > > cl_ = [v for k, v in pos.items() if k.startswith('CL')] > cl_pos = cl_[0] > if cl_pos > 0: > >blah.. > > > There are 2 issues with the above: > a. ugly -

Re: why del is not a function or method?

2017-10-16 Thread Peter Otten
bartc wrote: > On 16/10/2017 16:58, Stefan Ram wrote: >> Xue Feng writes: >>> I wonder why 'del' is not a function or method. >> >>Assume, >> >> x = 2. >> >>When a function »f« is called with the argument »x«, >>this is written as >> >> f( x ) >> >>. The function never gets t

Re: why del is not a function or method?

2017-10-16 Thread Peter Otten
Stefan Ram wrote: > Peter Otten <__pete...@web.de> writes: >>team.pop(2) >>Stefan's explanation may work for >>del x >>if you discard >>x = None # get rid of the huge object that x was bound to before >>as a hack > > »x = None« observabl

Re: Is there a function of ipaddress to get the subnet only from input like 192.168.1.129/25

2017-10-17 Thread Peter Otten
Daniel Flick wrote: > I am very new to Python and have been struggling to find some info on > processing IP addresses. > > get_network returns 192.168.1.128/25 but I need 192.168.1.128 only. I can > do this with netaddr but I am working with Mako templates and ipaddress is > a built in module so

Re: Is there a function of ipaddress to get the subnet only from input like 192.168.1.129/25

2017-10-17 Thread Peter Otten
Daniel Flick wrote: > On Tuesday, October 17, 2017 at 4:25:02 PM UTC-5, Daniel Flick wrote: >> >> Peter, I am not following. Are you saying that there is a function that >> returns the network only? network_address was giving me the mask >> attached to the end but

Re: How to debug an unfired tkinter event?

2017-10-19 Thread Peter Otten
jf...@ms4.hinet.net wrote: > In last few days, I tried to experiment with the scrolling table > implemented in canvas, started from this example: > http://code.activestate.com/recipes/580793-tkinter-table-with-scrollbars/. > Everything works fine until I moved the scrolling_area instance (which th

<    4   5   6   7   8   9   10   11   12   13   >