MemoryError and Pickle

2016-11-21 Thread Fillmore
Hi there, Python newbie here. I am working with large files. For this reason I figured that I would capture the large input into a list and serialize it with pickle for later (faster) usage. Everything has worked beautifully until today when the large data (1GB) file caused a MemoryError :(

Re: need some kind of "coherence index" for a group of strings

2016-11-03 Thread Fillmore
On 11/3/2016 6:47 PM, jlada...@itu.edu wrote: On Thursday, November 3, 2016 at 1:09:48 PM UTC-7, Neil D. Cerutti wrote: you may also be able to use some items "off the shelf" from Python's difflib. I wasn't aware of that module, thanks for the tip! difflib.SequenceMatcher.ratio() returns a nu

need some kind of "coherence index" for a group of strings

2016-11-03 Thread Fillmore
Hi there, apologies for the generic question. Here is my problem let's say that I have a list of lists of strings. list1:#strings are sort of similar to one another my_nice_string_blabla my_nice_string_blqbli my_nice_string_bl0bla my_nice_string_aru list2:#strings are mostly

loading trees...

2016-06-12 Thread Fillmore
Hi, problem for today. I have a batch file that creates "trees of data". I can save these trees in the form of python code or serialize them with something like pickle. I then need to run a program that loads the whole forest in the form of a dict() where each item will point to a dynamically l

Re: reduction

2016-06-01 Thread Fillmore
Thank you, guys. Your suggestions are avaluable. I think I'll go with the tree On 05/31/2016 10:22 AM, Fillmore wrote: My problem. I have lists of substrings associated to values: ['a','b','c','g'] => 1 ['a','b','c

reduction

2016-05-31 Thread Fillmore
My problem. I have lists of substrings associated to values: ['a','b','c','g'] => 1 ['a','b','c','h'] => 1 ['a','b','c','i'] => 1 ['a','b','c','j'] => 1 ['a','b','c','k'] => 1 ['a','b','c','l'] => 0 # <- Black sheep!!! ['a','b','c','m'] => 1 ['a','b','c','n'] => 1 ['a','b','c','o'] => 1 ['a','b

Python script reading from sys.stdin and debugger

2016-05-19 Thread Fillmore
Hello PyMasters! Long story short: cat myfile.txt | python -m pdb myscript.py doens't work (pdb hijacking stdin?). Google indicates that someone has fixed this with named pipes, but, call me stupid, I don't understand how I need to set up those pipes, how I need to modify my script and, abov

Re: I have been dealing with Python for a few weeks...

2016-04-18 Thread Fillmore
On 04/14/2016 10:12 PM, justin walters wrote: On Thu, Apr 14, 2016 at 1:50 PM, Fillmore wrote: ...and I'm loving it. Sooo much more elegant than Perl...and so much less going back to the manual to lookup the syntax of simple data structures and operations... REPL is so useful and you

I have been dealing with Python for a few weeks...

2016-04-14 Thread Fillmore
...and I'm loving it. Sooo much more elegant than Perl...and so much less going back to the manual to lookup the syntax of simple data structures and operations... REPL is so useful and you guys rock too cheers -- https://mail.python.org/mailman/listinfo/python-list

Re: one-element tuples

2016-04-11 Thread Fillmore
On 04/11/2016 10:10 AM, Grant Edwards wrote: What behaviour did you expect instead? That's still unclear. I must admit this is one of the best trolls I've seen in a while... shall I take it as a compliment? -- https://mail.python.org/mailman/listinfo/python-list

Re: one-element tuples

2016-04-10 Thread Fillmore
On 04/11/2016 12:10 AM, Ben Finney wrote: So, will we never get your statement of what surprised you between those examples? Clearly there is something of interest here. I'd like to know what the facts of the matter were; “beginner's mind” is a precious resource, not to be squandered. I thou

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Fillmore
On 04/10/2016 11:54 PM, Steven D'Aprano wrote: On Mon, 11 Apr 2016 12:48 pm, Fillmore wrote: funny, but it seems to me that you are taking it personally... thank god i even apologized in advance for what was most probably a stupid question.. I hope you did get a laugh out of it, becau

Re: one-element tuples

2016-04-10 Thread Fillmore
Thank you for trying to help, Martin. So: On 04/10/2016 09:08 PM, Martin A. Brown wrote: #1: I would not choose eval() except when there is no other solution. If you don't need eval(), it may save you some headache in the future, as well, to find an alternate way. So, can we hel

Re: one-element tuples

2016-04-10 Thread Fillmore
On 04/10/2016 09:36 PM, Ben Finney wrote: If the two examples give you different responses (one surprises you, the other does not), I would really like to know*what the surprise is*. What specifically did you expect, that did not happen? now that I get the role of commas it's not surprising any

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Fillmore
funny, but it seems to me that you are taking it personally... thank god i even apologized in advance for what was most probably a stupid question.. On 04/10/2016 09:50 PM, Steven D'Aprano wrote: Fillmore, you should feel very pleased with yourself. All the tens of thousands of P

Re: one-element tuples

2016-04-10 Thread Fillmore
On 04/10/2016 08:31 PM, Ben Finney wrote: Can you describe explicitly what that “discontinuation point” is? I'm not seeing it. Here you go: >>> a = '"string1"' >>> b = '"string1","string2"' >>> c = '"string1","string2","string3"' >>> ea = eval(a) >>> eb = eval(b) >>> ec = eval(c) >>> type(ea)

Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-10 Thread Fillmore
On 04/10/2016 08:13 PM, Fillmore wrote: Sorry guys. It was not my intention to piss off anyone...just trying to understand how the languare works I guess that the answer to my question is: there is no such thing as a one-element tuple, and Python will automatically convert a one-element

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Fillmore
On 04/10/2016 07:30 PM, Stephen Hansen wrote: There's nothing inconsistent or surprising going on besides you doing something vaguely weird and not really expressing what you find surprising. well, I was getting some surprising results for some of my data, so I can guarantee that I was surpris

one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-10 Thread Fillmore
Sorry guys. It was not my intention to piss off anyone...just trying to understand how the languare works I guess that the answer to my question is: there is no such thing as a one-element tuple, and Python will automatically convert a one-element tuple to a string... hence the behavior I obs

Most probably a stupid question, but I still want to ask

2016-04-10 Thread Fillmore
let's look at this: $ python3.4 Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> line1 = '"String1" | bla' >>> parts1 = line1.split(" | ") >>> parts1 ['"String1"', 'bla'] >>> tokens1 = eval(parts1[0]) >>

Re: Drowning in a teacup?

2016-04-01 Thread Fillmore
On 04/01/2016 04:27 PM, Fillmore wrote: notorious pass by reference vs pass by value biting me in the backside here. Proceeding in order. Many thanks to all of those who replied! -- https://mail.python.org/mailman/listinfo/python-list

Drowning in a teacup?

2016-04-01 Thread Fillmore
notorious pass by reference vs pass by value biting me in the backside here. Proceeding in order. I need to scan a list of strings. If one of the elements matches the beginning of a search keyword, that element needs to snap to the front of the list. I achieved that this way: for i in

retrieve key of only element in a dictionary (Python 3)

2016-03-19 Thread Fillmore
I must be missing something simple, but... Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> d = dict() >>> d['squib'] = "007" >>> # I forget that 'squib' is my key to retrieve the only element in d ... >

Re: retrieve key of only element in a dictionary (Python 3)

2016-03-18 Thread Fillmore
OK, this seems to do the trick, but boy is it a lot of code. Anythong more pythonic? >>> l = list(d.items()) >>> l [('squib', '007')] >>> l[0] ('squib', '007') >>> l[0][0] 'squib' >>> On 03/18/201

Re: Perl to Python again

2016-03-12 Thread Fillmore
On 03/12/2016 04:40 AM, alister wrote: On Fri, 11 Mar 2016 19:15:48 -0500, Fillmore wrote: I not sure if you were being accused of being lazy as such but actually being given the suggestion that there are other places that you can find these answers that are probably better for a number of

Re: Perl to Python again

2016-03-11 Thread Fillmore
On 3/11/2016 7:12 PM, Martin A. Brown wrote: Aside from your csv question today, many of your questions could be answered by reading through the manual documenting the standard datatypes (note, I am assuming you are using Python 3). are you accusing me of being lazy? if that's your accusatio

Perl to Python again

2016-03-11 Thread Fillmore
So, now I need to split a string in a way that the first element goes into a string and the others in a list: while($line = ) { my ($s,@values) = split /\t/,$line; I am trying with: for line in sys.stdin: s,values = line.strip().split("\t") print(s) but no luck: ValueError: t

Re: argparse

2016-03-11 Thread Fillmore
On 3/11/2016 6:26 PM, Larry Martell wrote: am I missing something obvious? https://docs.python.org/2/library/argparse.html#usage you rock! -- https://mail.python.org/mailman/listinfo/python-list

argparse

2016-03-11 Thread Fillmore
Playing with ArgumentParser. I can't find a way to override the -h and --help options so that it provides my custom help message. -h, --help show this help message and exit Here is what I am trying: parser = argparse.ArgumentParser("csresolver.py",add_help=False) parser.add_argumen

Re: issue with CVS module

2016-03-11 Thread Fillmore
On 3/11/2016 2:41 PM, Fillmore wrote: I have a TSV file containing a few strings like this (double quotes are part of the string): A big thank you to everyone who helped with this and with other questions. My porting of one of my Perl scripts to Python is over now that the two scripts

Re: issue with CVS module

2016-03-11 Thread Fillmore
On 3/11/2016 4:15 PM, Mark Lawrence wrote: https://docs.python.org/3/library/csv.html#csv.Dialect.doublequote thanks, but my TSV is not using any particular dialect as far as I understand... Thank you, anyway -- https://mail.python.org/mailman/listinfo/python-list

Re: issue with CVS module

2016-03-11 Thread Fillmore
On 3/11/2016 4:14 PM, MRAB wrote: >>> import csv >>> s = '"Please preserve my doublequotes"\ttext1\ttext2' >>> reader = csv.reader([s], delimiter='\t', quotechar=None) >>> for row in reader: ... print(row[0]) ... "Please preserve my doublequotes" >>> This worked! thank you MRAB --

Re: issue with CVS module

2016-03-11 Thread Fillmore
On 3/11/2016 2:41 PM, Fillmore wrote: Is there some directive I can give CVS reader to tell it to stop screwing with my text? OK, I think I reproduced my problem at the REPL: >>> import csv >>> s = '"Please preserve my doublequotes"\ttext1\ttext2' >

Re: issue with CVS module

2016-03-11 Thread Fillmore
On 3/11/2016 3:05 PM, Joel Goldstick wrote: Enter the python shell. Import csv then type help(csv) It is highly configurable Possibly, but I am having a hard time letting it know that it should leave each and every char alone, ignore quoting and just handle strings as strings. I tried pl

issue with CVS module

2016-03-11 Thread Fillmore
I have a TSV file containing a few strings like this (double quotes are part of the string): '"pragma: CacheHandler=08616B7E907744E026C9F044250EA55844CCFD52"' After Python and the CVS module has read the file and re-printed the value, the string has become: 'pragma: CacheHandler=08616B7E90

Re: non printable (moving away from Perl)

2016-03-11 Thread Fillmore
On 3/11/2016 2:23 PM, MRAB wrote: On 2016-03-11 00:07, Fillmore wrote: Here's another handy Perl regex which I am not sure how to translate to Python. I use it to avoid processing lines that contain funny chars... if ($string =~ /[^[:print:]]/) {next OUTER;} :) Python 3 (Unicode) st

Re: non printable (moving away from Perl)

2016-03-11 Thread Fillmore
On 03/11/2016 07:13 AM, Wolfgang Maier wrote: One lesson for Perl regex users is that in Python many things can be solved without regexes. How about defining: printable = {chr(n) for n in range(32, 127)} then using: if (set(my_string) - set(printable)): break seems computationally heav

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Fillmore
On 3/10/2016 7:08 PM, INADA Naoki wrote: No. I see it usually. Python's zen says: Errors should never pass silently. Unless explicitly silenced. When failed to write to stdout, Python should raise Exception. You can silence explicitly when it's safe: try: print(...) except Broken

non printable (moving away from Perl)

2016-03-10 Thread Fillmore
Here's another handy Perl regex which I am not sure how to translate to Python. I use it to avoid processing lines that contain funny chars... if ($string =~ /[^[:print:]]/) {next OUTER;} :) -- https://mail.python.org/mailman/listinfo/python-list

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Fillmore
On 3/10/2016 5:16 PM, Ian Kelly wrote: Interesting, both of these are probably worth bringing up as issues on the bugs.python.org tracker. I'm not sure that the behavior should be changed (if we get an error, we shouldn't just swallow it) but it does seem like a significant hassle for writing co

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Fillmore
On 3/10/2016 4:46 PM, Ian Kelly wrote: On Thu, Mar 10, 2016 at 2:33 PM, Fillmore wrote: when I put a Python script in pipe with other commands, it will refuse to let go silently. Any way I can avoid this? What is your script doing? I don't see this problem. ikelly@queso:~

Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Fillmore
when I put a Python script in pipe with other commands, it will refuse to let go silently. Any way I can avoid this? $ python somescript.py | head -5 line 1 line 3 line 3 line 4 line 5 Traceback (most recent call last): File "./somescript.py", line 50, in sys.stdout.write(row[0]) Broken

Re: breaking out of outer loops

2016-03-07 Thread Fillmore
On 3/7/2016 7:08 PM, Chris Angelico wrote: Yep, which is why we're offering a variety of new paradigms. Because it's ever so much easier to get your head around three than one! We are SO helpful, guys. So helpful. :) not too dissimilarly from human languages, speaking a foreign language is

Re: breaking out of outer loops

2016-03-07 Thread Fillmore
On 3/7/2016 6:09 PM, Fillmore wrote: I must be missing something simple because I can't find a way to break out of a nested loop in Python. Thanks to everyone who has tried to help so far. I suspect this may be a case where I just need to get my head around a new paradigm --

Re: breaking out of outer loops

2016-03-07 Thread Fillmore
On 3/7/2016 6:29 PM, Rob Gaddi wrote: You're used to Perl, you're used to exceptions being A Thing. This is Python, and exceptions are just another means of flow control. class MalformedLineError(Exception): pass for line in file: try: for part in line.split('\t'):

Re: breaking out of outer loops

2016-03-07 Thread Fillmore
On 3/7/2016 6:17 PM, Ian Kelly wrote: On Mon, Mar 7, 2016 at 4:09 PM, Fillmore wrote: I must be missing something simple because I can't find a way to break out of a nested loop in Python. Is there a way to label loops? No, you can't break out of nested loops, wow...this is

Re: Pythonic love

2016-03-07 Thread Fillmore
On 3/7/2016 6:03 PM, sohcahto...@gmail.com wrote: On a side note, your "with open..." line uses inconsistent quoting. > You have "" on one string, but '' on another. Thanks. I'll make sure I flog myself three times later tonight... -- https://mail.python.org/mailman/listinfo/python-list

breaking out of outer loops

2016-03-07 Thread Fillmore
I must be missing something simple because I can't find a way to break out of a nested loop in Python. Is there a way to label loops? For the record, here's a Perl script of mine I'm trying to port...there may be 'malformed' lines in a TSV file I'm parsing that are better discarded than fix

Pythonic love

2016-03-07 Thread Fillmore
learning Python from Perl here. Want to do things as Pythonicly as possible. I am reading a TSV, but need to skip the first 5 lines. The following works, but wonder if there's a more pythonc way to do things. Thanks ctr = 0 with open(prfile,mode="rt",encoding='utf-8') as pfile: for line i

Re: Regex: Perl to Python

2016-03-07 Thread Fillmore
Big thank you to everyone who offered their help! On 03/06/2016 11:38 PM, Fillmore wrote: -- https://mail.python.org/mailman/listinfo/python-list

Regex: Perl to Python

2016-03-06 Thread Fillmore
Hi, I'm trying to move away from Perl and go to Python. Regex seems to bethe hardest challenge so far. Perl: while () { if (/(\d+)\t(.+)$/) { print $1." - ". $2."\n"; } } into python pattern = re.compile(r"(\d+)\t(.+)$") with open(fields_Indexfile,mode="rt",encoding='utf-8') a

Re: Cygwin and Python3

2016-02-09 Thread Fillmore
On 2/9/2016 4:47 PM, Fillmore wrote: On 2/9/2016 3:30 PM, alvin.hacop...@gmail.com wrote: When you run the cygwin installer you have the option of installing 2.7 > and 3.2.5, by default it will install 2.7 and 3.2 together. > After running the installer run whereis python and u

Re: Cygwin and Python3

2016-02-09 Thread Fillmore
On 2/9/2016 3:30 PM, alvin.hacop...@gmail.com wrote: When you run the cygwin installer you have the option of installing 2.7 > and 3.2.5, by default it will install 2.7 and 3.2 together. > After running the installer run whereis python and use the alternatives > to change it or use python3 ins

Re: Cygwin and Python3

2016-02-09 Thread Fillmore
On 2/9/2016 2:29 PM, alvin.hacop...@gmail.com wrote: $ ls -l /usr/bin/python rm /usr/bin/python $ ln -s /usr/bin/python /usr/bin/python3.2m.exe $ /usr/bin/python --version Python 3.2.5 $ pydoc modules Still no luck (: ~ $ python --version Python 3.5.1 ~ $ python (..hangs indefinitel

Cygwin and Python3

2016-02-09 Thread Fillmore
Hi, I am having a hard time making my Cygwin run Python 3.5 (or Python 2.7 for that matter). The command will hang and nothing happens. A cursory search on the net reveals many possibilities, which might mean a lot of trial and error, which I would very much like to avoid. Any suggestions on h

Re: psss...I want to move from Perl to Python

2016-01-31 Thread Fillmore
On 01/30/2016 05:26 AM, wxjmfa...@gmail.com wrote: Python 2 vs python 3 is anything but "solved". Python 3.5.1 is still suffering from the same buggy behaviour as in Python 3.0 . Can you elaborate? -- https://mail.python.org/mailman/listinfo/python-list

Re: psss...I want to move from Perl to Python

2016-01-29 Thread Fillmore
On 1/29/2016 4:30 PM, Rick Johnson wrote: People who are unwilling to "expanding their intellectual horizons" make me sick!!! did I miss something or is this aggressiveness unjustified? -- https://mail.python.org/mailman/listinfo/python-list

Re: psss...I want to move from Perl to Python

2016-01-29 Thread Fillmore
previous versions? - Is there a good IDE that can be used for debugging? all free IDEs for Perl suck and it would be awesome if Python was better than that. Thanks On 1/28/2016 7:01 PM, Fillmore wrote: I learned myself Perl as a scripting language over two decades ago. All -- https

Re: psss...I want to move from Perl to Python

2016-01-29 Thread Fillmore
+1 On 1/29/2016 10:07 AM, Random832 wrote: The main source of confusion is that $foo[5] is an element of @foo. $foo{'x'} is an element of %foo. Both of these have absolutely nothing to do with $foo. -- https://mail.python.org/mailman/listinfo/python-list

Re: psss...I want to move from Perl to Python

2016-01-29 Thread Fillmore
So many answers. So much wisdom...thank you everyone On 01/28/2016 07:01 PM, Fillmore wrote: -- https://mail.python.org/mailman/listinfo/python-list

psss...I want to move from Perl to Python

2016-01-28 Thread Fillmore
I learned myself Perl as a scripting language over two decades ago. All through this time, I would revert to it from time to time whenever I needed some text manipulation and data analysis script. My problem? maybe I am stupid, but each time I have to go back and re-learn the syntax, the got