Re: [Tutor] Help with printing to text file

2016-02-01 Thread Cameron Simpson
e advantage of Alan's "put it in a list" approach is that you could separate the seaching of the CSV into one function returning a list, and then do whatever you want (eg print it to your file) as a wholy separate operation. Cheers, Cameron Simpson _

Re: [Tutor] 2016-02-01 Filter STRINGS in Log File and Pass as VARAIBLE within PYTHON script

2016-02-02 Thread Cameron Simpson
("i:", i) whoisVAR = os.popen("whois -H " + i + " |egrep -i \"name|country|mail\" |sort -u").read() Again, here you are running a shell pipeline which could be done in Python. Look at the subpr

Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-11 Thread Cameron Simpson
On 11Mar2016 21:31, boB Stepp wrote: I must be bored tonight. I have to confess that when copying and pasting from the interpreter into a plain text email, I often find it cluttered to confusing by all the ">>>..." that can result from nested quoting. So I poked around on the Internet and foun

[Tutor] avoiding top-posting in GMail (was: Changing the interpreter prompt symbol from ">>>" to ???)

2016-03-11 Thread Cameron Simpson
UTF-8" LC_MONETARY="en_GB.UTF-8" LC_NUMERIC="en_GB.UTF-8" LC_TIME="en_GB.UTF-8" LC_ALL= I think my terminal might be Unicode friendly... Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-12 Thread Cameron Simpson
pythonanywhere? All of this works fine with utf-8 there. Sounds like codeanywhere is an 8-bit environment. Maybe ISO8859-1 (untested assumption). Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscriptio

Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-12 Thread Cameron Simpson
On 12Mar2016 00:46, boB Stepp wrote: On Fri, Mar 11, 2016 at 11:02 PM, Cameron Simpson wrote: 0x25ba BLACK RIGHT-POINTING POINTER So it seems that your environment has chosen to transcribe your chr(26) and chr(16) into some glyphs for display, and matched those glyphs with suitable Unicode

Re: [Tutor] run local script on a remote machine

2016-10-27 Thread Cameron Simpson
ll on one line, BTW, in case your email reader folds things up.) So you might think: but then the shell _will_ see the "<" redirection! But of course that is the shell on the remote machine, and your script isn't on that machine, so the shell emits the error message you saw.

Re: [Tutor] Code not working advise pls

2016-11-04 Thread Cameron Simpson
tion and consider how it may help. If you come back with further queries, please include a cut/paste transcript of the your program's code, and a run of it with the output. (NB: cut/patse the text, don't attach a screenshot.) Cheers, Cameron Simpson _

Re: [Tutor] Total newbie question

2017-01-03 Thread Cameron Simpson
gdbm-dev, lzma-dev, libssl-dev, libreadline-dev, zlib1g-dev. Then do a clean configure again and see what it says. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Total newbie question

2017-01-03 Thread Cameron Simpson
On 03Jan2017 17:07, Peter Otten <__pete...@web.de> wrote: Cameron Simpson wrote: On 02Jan2017 17:21, MR ZenWiz wrote: I'm trying to install python 4.6 on my Xubuntu 16.04 desktop, [...] INFO: Can't locate Tcl/Tk libs and/or headers You lack the tk development libraries and

Re: [Tutor] Using venv

2017-01-27 Thread Cameron Simpson
l $HOME/bin directory, or source the venv's "activate" file from your shell's profile (this making the venv searched ahead of the system paths), etc. Or your launcher might simply invoke: $HOME/path/to/your/venv/bin/python you

Re: [Tutor] sort() method and non-ASCII

2017-02-05 Thread Cameron Simpson
ower case at 96 (2^6 + 2^32). Those values look rounder in base 16: 0x40 and 0x60. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] sort() method and non-ASCII

2017-02-05 Thread Cameron Simpson
TF-16 or UTF-32? No, different machines order the bytes in a larger word in different orders. "Big endian" machines like SPARCs and M68k etc put the most significant bytes first; little endian machines put the least significant bytes first (eg Intel architecture machines). (Asid

Re: [Tutor] os.symlink can't find target

2014-02-26 Thread Cameron Simpson
right thing to do. If you find yourself doing this, chances are you're trying to fix the wrong thing. You only need to escape strings when passing them to something that will be interpreting a line of text. Such as a piece of shell script. You should not need it to pass strings to something th

Re: [Tutor] os.symlink can't find target

2014-02-26 Thread Cameron Simpson
y, no. pathList[j] can contain either .mp3 files or .flac > files. Except that I thought this was inside the if-statement, so you know that this time it is an mp3. Cheers, -- Cameron Simpson Trust the computer industry to shorten Year 2000 to Y2K. It was this thinking that caused the pro

Re: [Tutor] improvements on a renaming script

2014-03-10 Thread Cameron Simpson
oin(indir,f),os.path.join( > outdir, > > get_long_name(get_slice(f))+"_-_"+get_bn_seq(f)+".jpeg") > ) I'd preceed the rename() by computing: oldname = os.path.join(indir,f)

Re: [Tutor] improvements on a renaming script

2014-03-10 Thread Cameron Simpson
tain TAB character, it will contain spaces. Cheers, -- Cameron Simpson Wirth's Law: Software is getting slower more rapidly than hardware becomes faster. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription

Re: [Tutor] please help

2014-03-21 Thread Cameron Simpson
nce of characters, you can write: for c in line2: ... collect statistics about c ... ... print report ... I would collect the statistics using a dictionary to keep count of the characters. See the dict.setdefault method; it should be helpful. Cheers, -- Cameron Simpson ... in '59

Re: [Tutor] please help

2014-03-22 Thread Cameron Simpson
On 22Mar2014 00:04, Mark Lawrence wrote: > On 21/03/2014 21:39, Cameron Simpson wrote: > >On 21Mar2014 20:31, Mustafa Musameh wrote: > > > >I would collect the statistics using a dictionary to keep count of > >the characters. See the dict.setdefault m

Re: [Tutor] character counting

2014-03-23 Thread Cameron Simpson
in Ks: > print sum(counters.itervalues()) This prints the same sum as many times as there are keys. Notice that your print statement has no mention of "k"? You either want just the "print" with no loop over Ks or you want the loop, with some expression inside which ch

Re: [Tutor] When to use classes

2014-04-09 Thread Cameron Simpson
ually). - later, if need be, you can change the inner workings of how ObjNames work without changing the main code, or at least not much - sometimes not at all Anyway, that's an ok rule of thumb for when to make a class: when you have a bunch of operations to do to one type of thing. C

Re: [Tutor] Keeping change-in-place vs. copy methods straight

2014-05-04 Thread Cameron Simpson
any particular function. But it is a good practice to adopt in one's own code. As you suggest, this keeps the two notions separate by making their use in the code distinct. Cheers, Cameron Simpson Too young to rest on the weekend, too old to rest during the week.

Re: [Tutor] (no subject)

2014-05-14 Thread Cameron Simpson
all the loops. It can at best print the last line of the file. I do not know what you actaully intend here. See if any of these suggestions help you progress with your program, and report back (by replying to this thread) when you have new problems or new questions. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] While truth

2014-05-20 Thread Cameron Simpson
zero length strings, etc) are "false", and most other things are "true". Cheers, Cameron Simpson Rugby is a beastly game played by gentlemen; soccer is a gentleman's game played by beasts; football is a beastly game played by beasts. - Henry Blaha __

Re: [Tutor] I am having difficulty grasping 'generators'

2014-05-28 Thread Cameron Simpson
"wanted" list and the return statement. The calling code is the same. To see the difference, put a "print" in "wanted_lines" as the first line of the for loop. With the "list" version you will see all the prints run before you get the array back. Wit

Re: [Tutor] pipes and redirecting

2014-05-28 Thread Cameron Simpson
od on a string, or even better: don't you already know the arguments for your "dd"? Just fill them out directly rather than backtracking from a string. However, your recipe is very close. Change: p2 = subprocess.Popen(compress, stdin=p1.stdout, stdout=subprocess.PIPE) into:

Re: [Tutor] Pease help

2014-06-07 Thread Cameron Simpson
'): print 'Please enter a yes or no' [...] Based on the suggested change earlier, this loop should then be followed by: endProgram = (endProgram == 'yes') to get a Boolean value for the loop control variable "endProgram". Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] code review

2014-06-12 Thread Cameron Simpson
melcase in Python names is class names "This That". It doesn't affect your code in any functional way, but others will find you code slightly more readable. These common conventions are outlined in PEP 8: http://legacy.python.org/dev/peps/pep-0008/ Worth a read. It is o

Re: [Tutor] code review

2014-06-12 Thread Cameron Simpson
On 13Jun2014 12:28, Cameron Simpson wrote: snap_path = os.path.join(VXGEN_DIR, snapName) backupList.append(snap_name) Sorry, "snap_path" in both lines:-( Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread Cameron Simpson
y a tuple later" effect, just write it all with lists; it will be simpler. You can always come back later after the code is functioning correctly and think about tuples. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Why is Quick Search at docs.Python.org so useless?

2014-07-06 Thread Cameron Simpson
Not a fix, but I for one always start at the index: https://docs.python.org/3/genindex.html (or the python 2 version) for ad hoc stuff. For speed and convenience I always have a fairly current copy of the docs on my desktop, making browsing them near instant. -- Each new user of a new syst

Re: [Tutor] How can I open and use gnome-terminal from a Python script?

2014-07-08 Thread Cameron Simpson
n't helped. os.system should be documented in the "os" module. But it just takes a shell command, so aside for handling the fork/exec-of-"sh -c your_command"-wait, there is little to document. Cheers, Cameron Simpson __

Re: [Tutor] How can I open and use gnome-terminal from a Python script?

2014-07-08 Thread Cameron Simpson
from Python? os.chdir("the/proper/directory") os.system("/bin/activate") Because "activate" needs to be sourced by the shell. It hacks the environment. Cheers, Cameron Simpson If at first you don't succeed, your sky-diving days are over. - Paul

Re: [Tutor] How can I open and use gnome-terminal from a Python script?

2014-07-09 Thread Cameron Simpson
. When searching for doco on particular functions I find the Index is a good place. Go to the "S" section and find "system"; there should be a link directly to the relevant doc section. Cheers, Cameron Simpson In theory, there is no difference between theory and practice. I

Re: [Tutor] How can I open and use gnome-terminal from a Python script?

2014-07-09 Thread Cameron Simpson
your pain. Eg: #!/bin/sh . /path/to/venv/bin/activate exec "${SHELL:-/bin/sh}" Cheers, Cameron Simpson Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal. - Friedrich Nietzsche ___ Tutor maillist - Tu

Re: [Tutor] How does this work (iterating over a function)?

2014-07-09 Thread Cameron Simpson
e and does whatever. Next time the for loop iterates the "fibonacci" function runs again, briefly, until the next "yield". I hope this helps you visualise the process. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] plz find error

2014-07-10 Thread Cameron Simpson
supplying some code without any accompanying text isn't very helpful to the people who may help you. Thanks, Cameron Simpson ... It beeped and said "Countdown initiated." Is that bad? ___ Tutor maillist - Tutor@python.org To unsubs

Re: [Tutor] sometimes I feel like my head is going to explode

2014-07-10 Thread Cameron Simpson
r things (often by getting good at stitching your smaller things together). You'll always need to consult doco for specifics and for anything new. Don't worry too much about that. Cheers, Cameron Simpson Serious error. All shortcuts have disappeared. Screen. Mind. Both are blank. - H

Re: [Tutor] How can I open and use gnome-terminal from a Python script?

2014-07-11 Thread Cameron Simpson
rog/Python/breezygui; . ./bin/activate; gnome-terminal"]) That is only one line, in case some mail program breaks it up. If you were using another terminal emulator it might be worth putting more work into getting stuff done after starting the emulator rather than before, but IMO gnome-ter

Re: [Tutor] Python 2 Vs python 3

2014-07-15 Thread Cameron Simpson
blem that you expect. Cheers, Cameron Simpson An ambassador is a man of virtue sent to lie abroad for his country; a news- writer is a man without virtue who lies at home for himself. - Sir Henry Wotton, Reliquae Wottonianae ___ Tutor maillist

Re: [Tutor] Using subprocess on a series of files with spaces

2014-07-31 Thread Cameron Simpson
and, and that form DOES NOT pass anything to the shell. The command gets executed directly. And therefore no spaces need escaping at all. Just getting this out before we further confuse the OP. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@pyt

Re: [Tutor] New to Python - print function - invalid syntax

2014-08-04 Thread Cameron Simpson
>>> print("hi", end=" ") hi >>> The "$" is my prompt. Any Python 3 should accept your print() call. The default system "python" on most platforms is still Python 2; that may be misleading you. In particular, if you're runnin

Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-17 Thread Cameron Simpson
em. for line_number, row in enumerate(catalog2): for col, item in enumerate(row): if lens[col] < len(item): lens[col] = len(item) The above code has no indentation. Was it indented when you wrote it? Cheers, Cameron Simpson Having been erased, The document you're seeking M

Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-18 Thread Cameron Simpson
e last line, which would normally be indented further than the "if". Cheers, Cameron Simpson This information is absolutely reliable; I read it on Usenet somewhere. - sc...@festival.ed.ac.uk (Scott Larnach) ___ Tutor maillist - Tutor@

Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-19 Thread Cameron Simpson
is not helped by the fact that for some things the GMail/GGroups HTML looks ok but the associated plain text version that they generate and send is usually awful. Cheers, Cameron Simpson A ridiculous place! Leaping from one bump to another, 187 corners or whatever it was! The number of time

Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-19 Thread Cameron Simpson
code fragile in one sense, it prevents it _silently_ misinterpreting one thing as another, and that is usually best. Cheers, Cameron Simpson The aim of AI is to make computers act like the ones in the movies. - Graham Mann ___ Tutor maillist

Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-19 Thread Cameron Simpson
n two items in it. We'd need to see to say. Try this: for element in row: print(element) col, item = element lens[col].append(len(item)) and see what you get. Cheers, Cameron Simpson Archiving the net is like washing toilet paper! - Leader Kibo

Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-19 Thread Cameron Simpson
minds me of a programmed cell of a spreadsheetkind of. It is very like that, if you consider two spreadsheet columns, the first with the original values in "lens" and the second having "max(col)" for each. Cheers, Cameron Simpson ERROR 155 - You can&

Re: [Tutor] Parsing txt file

2014-08-20 Thread Cameron Simpson
n the first colon and the trimming the whitespace from the two piece is simpler and gets you a more reliable parse. Cheers, Cameron Simpson Trust the computer industry to shorten Year 2000 to Y2K. It was this thinking that caused the problem in the first place. - Mark Ovens _

Re: [Tutor] Question

2014-08-21 Thread Cameron Simpson
ram and we'll see where we are. Cheers, Cameron Simpson ... and that was only one of many occasions on which I met my death, an experience which I don't hesitate to recommend strongly. - Baron von Munchausen ___ Tutor maillist - Tuto

Re: [Tutor] Interacting with stderr

2014-08-27 Thread Cameron Simpson
tderr=open('stderr.out', 'w') in your call() call. Then open 'stderr.out' and look for the relevant information. Obviously in a "real" program you'd take care to make that a temporary file with a unique name using the functions from the "tempf

Re: [Tutor] Interacting with stderr

2014-08-27 Thread Cameron Simpson
derr now xit = P.wait() if xit != 0: ... command was unsuccessful, complain, maybe abort ... Cheers, Cameron Simpson ep0: 3c509 in test mode. Erase pencil mark! This means that someone has scribbled with pencil in the test area on the card. Erase the pencil mark a

Re: [Tutor] Interacting with stderr

2014-08-27 Thread Cameron Simpson
communicate. Using .pipe keeps the requirements on me clear and leaves me maximum flexibility to handle I/O and process completion as I see fit. As you can see from my example code, it is hardly difficult to use Popen directly in the OP's use case, and arguably better. Cheers, Cameron

Re: [Tutor] Interacting with stderr

2014-08-27 Thread Cameron Simpson
nicate and (less so) call is that they do so much. When a particular part isn't working, figuring out what to fix is harder. On a tutor list, what's our stance on exploring the operation at a lower level so the OP gets a better feel for what's going on? I'm aware we don'

Re: [Tutor] Interacting with stderr

2014-08-28 Thread Cameron Simpson
ssful, complain, maybe abort ... Please try adapting your Python code to that and see where you end up. Put a print statement as the first line in the for-loop so you can see if you are receiving stderr lines as intended. Cheers, Cameron Simpson As soon as we started programming, we found t

Re: [Tutor] Import from project's lib directory?

2014-08-28 Thread Cameron Simpson
it prepends "$PWD/lib/python" to $PYTHONPATH, as that is where my modules live. In this way it runs the hacked module instead of running the "official" version. The OP would prepend "$PWD/lib" in the same scenario. Cheers, Cameron Simpson Invoking t

Re: [Tutor] Regression analysis using statsmodels: linear combinations

2014-08-28 Thread Cameron Simpson
em to have a dedicated mailing list. Shakoor, if you get no responses here, ask again on python-list: I know there are some statistics and floating point savvy people there. Cheers, Cameron Simpson To be positive: To be mistaken at the top of one's voice. Ambrose Bierce (1842-1914), U

Re: [Tutor] Quick question for Tutor admin.

2014-08-28 Thread Cameron Simpson
. If your screenshot is inherently graphical, publish it elsewhere (eg save it to Dropbox and get a "public link") and mention the link in your post, with some textual description. But for text, we like it inline in the message itself. Cheers, Cameron Simpson in rec.moto, jsh w

Re: [Tutor] Regression analysis using statsmodels: linear combinations

2014-08-28 Thread Cameron Simpson
On 29Aug2014 08:45, Cameron Simpson wrote: It looks like he's using this: http://statsmodels.sourceforge.net/ Works in python 2 and 3, but does not seem to have a dedicated mailing list. Hmm. There's a mailing list here: https://groups.google.com/forum/?hl=en#!forum/pystatsmodel

Re: [Tutor] Interacting with stderr

2014-08-29 Thread Cameron Simpson
ause my laptop has a mail system which will queue messages and send when I'm online again. But I _can't_ go and get your URL, because I'm offline. Please use inline plain text when you can. It helps everyone. Wow i feel like such an idiot haha. I should have caught that cap

Re: [Tutor] Interacting with stderr

2014-08-29 Thread Cameron Simpson
ry. It is often _easy_, but it leaves your systems at much greater risk. Cheers, Cameron Simpson Please do not send me Microsoft Word files. http://en.nothingisreal.com/wiki/Please_don't_send_me_Microsoft_Word_documents ___ Tutor maillist -

Re: [Tutor] Interacting with stderr

2014-08-30 Thread Cameron Simpson
process1 and or proc.name == process2: or perhaps: if proc.name in (process1, process2): and your psutil.Popen call looks... confused. Popen is a subprocess function, not part of psutil (I think). And you don't use either "out" or "err" after you collect them, so why use

Re: [Tutor] Good Text Editor/IDE for Python

2014-08-31 Thread Cameron Simpson
en I need an extra terminal for something short term. Just recently, I've customised my interactive Python with a powerful set of tab completion commands, similar to that provided by IPython. While typing, if I hit tab, it will try to complete the current variable, function, module or f

Re: [Tutor] Good Text Editor/IDE for Python

2014-09-01 Thread Cameron Simpson
On 01Sep2014 23:59, Steven D'Aprano wrote: On Mon, Sep 01, 2014 at 11:57:08AM +1000, Cameron Simpson wrote: On 01Sep2014 11:13, Steven D'Aprano wrote: >Just recently, I've customised my interactive Python with a powerful set >of tab completion commands, similar to tha

Re: [Tutor] New to Python..Need help

2014-09-04 Thread Cameron Simpson
single flat directory. Cheers, Cameron Simpson Knox's box is a 286. Fox in Socks does hacks and tricks Knox's box is hard to fix. To fix poor Knox's box for kicks. - David Mar , as quoted by John Mackin ___

Re: [Tutor] Vol 127, Issue 15

2014-09-05 Thread Cameron Simpson
mpt will help). 3: Please cut/paste your code instead of retyping it. You spell "Subprocess" above with a capital "S", which it does not have. This leads me to think the above it not your exact running code. Cheers, Cameron Simpson Nonsense. Space is blue, and birds

Re: [Tutor] print date and skip any repeats

2014-09-17 Thread Cameron Simpson
st the actualy code and a description of what it seems to be doing wrong. Cheers, Cameron Simpson Trust the computer industry to shorten Year 2000 to Y2K. It was this thinking that caused the problem in the first place. - Mark Ovens ___ Tutor ma

Re: [Tutor] Python Assignment Expression and Callable Expression

2014-09-18 Thread Cameron Simpson
must) access "self" to do its work. I think you are forgetting that the @decorator action occurs at the time the class is defined, not at the time the function is called. Cheers, Cameron Simpson More computing sins have been committed in the name of performance, without necessariliy

Re: [Tutor] Converting timestamp read as str to "full date and time"

2014-09-19 Thread Cameron Simpson
my_date)) Seriously, keep that steps all broken out separately like the above. Easier to read, easier to debug, easier to move relevant parts off into utility functions later when you need to do this from several places in your code. Cheers, Cameron Simpson If this experiment we're doing wor

Re: [Tutor] Is there a convenient table of Python 3.4 exceptions?

2014-10-24 Thread Cameron Simpson
os.unlink(some_pathname) os.rename(this, that) because a failed operation will raise an exception. Cheers, Cameron Simpson Mike was a sportbike rider, He'd say "El grande numero one!" With a 'No Fear' sticker on his zx11, he'd lightem'up just for fun...

Re: [Tutor] Would somebody kindly...

2014-10-28 Thread Cameron Simpson
he same as the loop variable. It is the same in this case because this is the idiomatic way to select particular values form an existing list. If we'd wanted the new list to contain double the original values we'd write: [ pair*2 for pair in values if key == pair[0] ] Cheers, Came

Re: [Tutor] Would somebody kindly...

2014-10-29 Thread Cameron Simpson
On 28Oct2014 21:33, Clayton Kirkwood wrote: !From: Cameron Simpson [mailto:c...@zip.com.au] !Let me try a less wordy diagram. You will need to be displaying in a !constant width font :-) ! ! [ pair for pair in values if key == pair[0] ] ! -- the expression that accrues in the

Re: [Tutor] Would somebody kindly...

2014-10-29 Thread Cameron Simpson
f" expression is true). So, the expression in the examples above is true only for the second tuple. So the expression "pair[1]" is only used for that tuple. And so the final result is a single element list with a "4", taken from the second tuple. Maybe this makes thi

Re: [Tutor] Subprocess how to use?

2014-11-05 Thread Cameron Simpson
fields = line.split() # read a line from "intersectBed" as words cut_fields = fields[3:8] # get columns 4..8 (counting from zero, not one) if cut_fields != old_fields:# this does what "uniq" does print cut_fields old_fields = cut_fields P.wait() # finished reading output, wait for process and tidy up Hopefully this suggests some ways forward. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Subprocess how to use?

2014-11-06 Thread Cameron Simpson
/327/ Instead you will usually use a call like this: db_handle.execute("INSERT into Table1 values(?,?)", value1, value2) and the .execute function will itself call the right SQL quoting function and replace the "?" for you. Cheers, Cameron Simpson ... It beeped and said &q

Re: [Tutor] How python keeps track of objects

2014-11-23 Thread Cameron Simpson
not available outside the function, and if you use a variable of that name elsewhere, it too is independent. Cheers, Cameron Simpson Fear the government that fears your computer. - Jon Drukman ___ Tutor maillist - Tutor@python.org To unsubscri

Re: [Tutor] multiprocessing question

2014-11-23 Thread Cameron Simpson
ybe return both the offset and line text). That is a byte offset to be used later. Cheers, Cameron Simpson George, discussing a patent and prior art: "Look, this publication has a date, the patent has a priority date, can't you just compare them?" Paul Sut

Re: [Tutor] urllib confusion

2014-11-23 Thread Cameron Simpson
have now. It is very popular and widely liked. Cheers, Cameron Simpson 'Supposing a tree fell down, Pooh, when we were underneath it?' 'Supposing it didn't,' said Pooh after careful thought. ___ Tutor maillist - Tutor@python.or

Re: [Tutor] multiprocessing question

2014-11-24 Thread Cameron Simpson
On 24Nov2014 12:56, Albert-Jan Roskam wrote: > From: Cameron Simpson On 23Nov2014 22:30, Albert-Jan Roskam wrote: I created some code to get records from a potentially giant .csv file. This implements a __getitem__ method that gets records from a memory-mapped csv file. In order for t

Re: [Tutor] multiprocessing question

2014-11-28 Thread Cameron Simpson
, great tip. I just modified some sample code that I post shortly. Note that the readahead stuff might mank the use of tell() to record the offset before reading each line. Cheers, Cameron Simpson The first ninety percent of the task takes ninety percent of the time, and the la

Re: [Tutor] multiprocessing question

2014-11-28 Thread Cameron Simpson
you're making lots of little updates. See sig quote. Cheers, Cameron Simpson The Eight Fallacies of Distributed Computing - Peter Deutsch 1. The network is reliable 2. Latency is zero 3. Bandwidth is infinite 4. The network is secure 5. Topology doesn't cha

Re: [Tutor] A small project

2014-12-02 Thread Cameron Simpson
oolkit and data storage specificly). (2) Get it working in as simple a way as possible. The GUI toolkit aside, the rest of it is probably easy to change if needed. But make it work _first_. Cheers, Cameron Simpson Of course I believe that solipsism is the correct philosophy, but that&#

Re: [Tutor] Need help!

2014-12-12 Thread Cameron Simpson
t would be unusual for that to be your only choice unless you have a specific task in mind. Cheers, Cameron Simpson Sometimes the only solution is to find a new problem. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription opti

Re: [Tutor] Could you look over my code?

2015-01-04 Thread Cameron Simpson
itself here: https://www.macports.org/ Then install python 3 by issuing the command: sudo port install python34 what as I type gets you python 3.4.2. The command: port search python found the name "python34" for me towards the bottom of the listing. Cheers, Cameron Simpson Mac OS X. Bec

Re: [Tutor] threading in python 2.7 - 2nd version

2015-01-04 Thread Cameron Simpson
delay(2000) def cleanup(): global exitFlag exitFlag = 1 print "Exit flag value: ", exitFlag for t in threads: t.join() sys.exit() Cheers, Cameron Simpson Out of memory. We wish to hold the whole sky, But we never will. - Haiku Error Messages

Re: [Tutor] regex advice

2015-01-06 Thread Cameron Simpson
ted word boundaries and nongreedy matches. You don't need them. Use this: \([a-zA-Z]\w*\)(\([^)]*\)) which matches any "foo(blah)". Then look at the returned match object and check that .group(1) == "t". Cheers, Cameron Simpson I heard a funny one this weekend

Re: [Tutor] Class errors

2015-01-22 Thread Cameron Simpson
ings I cannot be sure - it may just be a mistake - but "job.py" defines a class "Jobs". In "trial.py" you use the name "Job". Not the same! Cheers, Cameron Simpson Beware of bugs in the above code; I have only proved it correct, not tried it. - Donald E

Re: [Tutor] R: Re: Re: Re: Class learning

2015-01-23 Thread Cameron Simpson
uri @property def key(self): return self.method, self.uri Here the .key property happens to be a (method, uri) tuple. Might change in the future if that is not enough to uniquely identify the node. Cheers, Cameron Simpson Surely it was of this place, now Cambridge but formerly known

Re: [Tutor] R: Re: Re: Re: Class learning

2015-01-23 Thread Cameron Simpson
On 24Jan2015 00:47, Alan Gauld wrote: On 24/01/15 00:37, Cameron Simpson wrote: By contrast, I use it a far bit (though still far less than non-property methods). Generally for derived properties which are: - cheap to compute i.e. O(1) - which I want to abstract - usually represent some

Re: [Tutor] R: Re: Re: Re: Class learning

2015-01-24 Thread Cameron Simpson
On 24Jan2015 09:16, Alan Gauld wrote: On 24/01/15 01:50, Cameron Simpson wrote: On 24Jan2015 00:47, Alan Gauld wrote: But why a property rather than a simple method? Because it is a value that feels like an attribute. OK, Having seen Dannys reply as well as yours I guess I see the

Re: [Tutor] R: Re: Re: Re: Class learning

2015-01-24 Thread Cameron Simpson
On 24Jan2015 15:03, Mark Lawrence wrote: On 24/01/2015 01:50, Cameron Simpson wrote: My intuition is that a function is costly (potentially) and that consulting an attribute is very cheap. I don't want to break such intuition. It's not just your intuition, it's a fact. Fun

Re: [Tutor] os module question

2015-02-02 Thread Cameron Simpson
hostname That gets this machine's hostname. The OP wants to use an arbitrary machine's hostname, since he's looking up an asset db. He needs to use the sys.argv array. (We he's doing as it turns out, so not to worry.) Cheers, Cameron Simpson I must really get a thi

Re: [Tutor] What are *appropriate* uses for exec() and eval() ?

2015-02-16 Thread Cameron Simpson
ardwired, not obtained from elsewhere in any form. Like all sane people, I consider using exec() a code smell: if you're using it you should consider heavily alternatives to it. Cheers, Cameron Simpson I think... Therefore I ride. I ride... T

Re: [Tutor] Help with python in MAC OS 10.6

2015-02-27 Thread Cameron Simpson
irtualenv directory, avoiding conflicts with other systems like OSX or MacPorts. This is great for experimentation of maintaining special setups of your own. You can base the virtualenv of any of the installed Pythons (OSX, MacPorts, whatever), to get the installed libraries for free. Please

Re: [Tutor] Variable data to CSV

2015-02-28 Thread Cameron Simpson
: # at start of script: counts = {} # dict of counter based on port (or better, (device, port)) # when new device seen (nb: possibly print out accumulated prior count value) count[port] = 0 # when new error seen count[port] += 1 Chase CSV as a totally separat thing later; just use print()

Re: [Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?

2015-03-20 Thread Cameron Simpson
be in the context of "in Python", no other quibbles. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?

2015-03-21 Thread Cameron Simpson
rious kinds come into play: an external process of some kind which monitors the primary process (or something it manages), and take action if the primary process goes away or some activity does not occur for a period. Cheers, Cameron Simpson Cordless hoses have been around for quite some ti

Re: [Tutor] Why does print(a_list.sort()) return None?

2015-03-28 Thread Cameron Simpson
t [0, 1, 2, 4, 5] >>> The assignment has no return value. The .sort() call returns None, so the interpreter prints nothing. The expression "a_list" is of course the list, which is printed. Just to be glaingly obvious about this aspect of the interactive interpreter: >>>

Re: [Tutor] trying to convert pycurl/html to ascii

2015-03-29 Thread Cameron Simpson
is page: http://pycurl.sourceforge.net/doc/unicode.html which looks like it ought to discuss your problem. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread Cameron Simpson
n more normally and just name in instead of inlining a lambda. But sometimes (rarely) that makes for harder to read code structure (though easier to read function internals). Anyway, faced with a desire to use a lambda here, I would choose a tuple. Cheers, Cameron Simpson This is my sim

<    1   2   3   4   >