Re: Fast forward-backward (write-read)
On 10/23/2012 04:19 PM, David Hutto wrote:
Whether this is fast enough, or not, I don't know:
well, the OP's original post started with
"I am working with some rather large data files (>100GB)..."
filename = "data_file.txt"
f = open(filename, 'r')
forward = [line.rstrip('\n') for line in f.readlines()]
f.readlines() will be big(!) and have overhead... and forward results in
something again as big.
backward = [line.rstrip('\n') for line in reversed(forward)]
and defining backward looks to me to require space to build backward and
hold reversed(forward)
So, let's see, at that point in time (building backward) you've got
probably somewhere close to 400-500Gb in memory.
My guess -- probably not so fast. Thrashing is sure to be a factor on
all but machines I'll never have a chance to work on.
f.close()
print forward, "\n\n", "\n\n", backward, "\n"
It's good to retain context.
Emile
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to only get a list of the names of the non-directory files in current directory ('.')?
On 11/06/2012 03:12 PM, iMath wrote: how to get a list of names of everything in the current directory ? Start by working through the tutorial to get familiar with python at http://docs.python.org/2/tutorial/ then for your specific question, review the content at http://www.diveintopython.net/file_handling/os_module.html Emile BTW, googling for "python how to get a list of names of everything in the current directory" yields some good information as well. Google is your friend for this level of question. Not sure anymore beyond that... -- http://mail.python.org/mailman/listinfo/python-list
Re: How to only get a list of the names of the non-directory files in current directory ('.')?
On 11/13/2012 01:19 PM, Chris Angelico wrote: Troll fail. *whoops* *sigh* mine too. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: 10 sec poll - please reply!
On 11/20/2012 04:18 AM, Michael Herrmann wrote:
Hi,
I'm developing a GUI Automation library (http://www.getautoma.com) and am
having difficulty picking a name for the function that simulates key strokes. I
currently have it as 'type' but that clashes with the built-in function.
Example uses of 'type':
type(ENTER)
type("Hello World!")
type(CTRL + 'a')
What, in your view, would be the most intuitive alternative name?
Here are my thoughts so far: I could call it 'press'
I have several tools that distinguish between press and release for
this. You may want to consider having both.
Emile
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to use the python to do the unit test
On 11/20/2012 09:40 AM, [email protected] wrote: I write a mfc application, then I want to use the python to test this application. just as user click that button. Please tell me how to write the python application? I currently use MacroScheduler (http://www.mjtnet.com/) then write macros from within python and run them using the commands module to test. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: os.popen and the subprocess module
On 11/29/2012 10:39 AM, Nobody wrote: Every time I see your posts "Shanghai Noodle Factory" sticks in my head as my daily hummer. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Migrate from Access 2010 / VBA
On 11/29/2012 02:46 AM, Nicolas Évrard wrote: I'd like to add to the list Tryton http://www.tryton.org/ Which framework can be used to create a business application Let me second this, although for openERP (the parent from which Tryton was forked)... Reporting is done through relatorio (http://relatorio.openhex.org/), which uses ODF templates to generate ODF reports (or other format thanks to unoconv) the client is written in GTk (we're writing one in JavaScript right now (and I miss python badly)). ... for which the web client is fully up and running. In any case it's a rich environment for business applications. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: how to automate java application in window using python
On 09/18/2016 06:37 PM, Lawrence D’Oliveiro wrote: On Monday, September 19, 2016 at 11:32:25 AM UTC+12, Michael Torrie wrote: One I've used is AutoIt. <https://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F> Like I said, this kind of thing can never work reliably... Hmm, then I'll have to wait longer to experience the unreliability as the handful of automated gui tools I'm running has only been up 10 to 12 years or so. Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 2.x and 3.x usage survey
On 01/02/2014 08:55 AM, Grant Edwards wrote: On 2013-12-31, Steven D'Aprano wrote: You laugh, but there was at least one attendee at the last PyCon who was still using 1.5 professionally. Software never quite dies so long as there is hardware capable of running it. ITYM: ... so long as there is hardware capable of running an emulator that is capable of running it. ...or as long as there's business value in keeping it running. As I recall it took the banking industry decades to move things forward. I still maintain software for customers that I originally wrote 35 years ago. Rule one is don't fix it if it ain't broke, so yes, I've got python projects deployed that run under everything from 1.5.2 on. Fortunately, they all work without issue so maintenance isn't a problem. Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: What's correct Python syntax?
On 01/14/2014 02:05 PM, Terry Reedy wrote:
On 1/14/2014 3:46 AM, Igor Korot wrote:
Hi, ALL,
I'm trying to process a file which has following lines:
192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30
However, I don't need all the protocol info. All I'm interested in is
the last field, which is length.
To directly extract only the needed info:
>>> s="192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200,
length 30"
>>> s[s.rindex(' ')+1:]
'30'
Any particular reason to prefer that over:
>>> s.split()[-1]
'30'
Is it a length of s and speed or rindex over build and toss the list
kind of thing?
Emile
--
https://mail.python.org/mailman/listinfo/python-list
Re: dictionary with tuples
On 01/14/2014 02:00 PM, Tobiah wrote:
On 01/14/2014 01:21 PM, YBM wrote:
Le 14/01/2014 22:10, Igor Korot a écrit :
Hi, ALL,
C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
dict = {}
dict[(1,2)] = ('a','b')
dict[(3,4)] = ('c','d')
for (key1,key2),(value1,value2) in dict:
... print key1, " ", key2
... print value1, " ", value2
...
Traceback (most recent call last):
File "", line 1, in
TypeError: 'int' object is not iterable
What am I doing wrong?
for ... in dict:
is a way to iterate through dictionnary items,
what you want to do can be done so:
for (key1,key2),(value1,value2) in dict.items():
But it's (key1, value1), (key2, value2)
No it isn't. :)
Emile
--
https://mail.python.org/mailman/listinfo/python-list
Add followers at time of import
Hi Ethan, How hard would it be to add a follower to a transaction (PO or Sales Order) at time of import if the account has that follower? IOW, Ron follows 'hilltop ranch' -- he'd like all activity linked to 'hilltop ranch' to include him as a follower. Right now, following the account doesn't notify about changes to documents, only changes to the account itself. Ask if that's not clear. Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Add followers at time of import
On 01/21/2014 10:03 AM, Chris Angelico wrote: On Wed, Jan 22, 2014 at 4:52 AM, emile wrote: Ask if that's not clear. I'm not entirely sure, but I think this might have been meant for somewhere other than python-list. Welcome to the club. Aargh! -- I hate when that happens... Sorry. Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Modifying the default argument of function
Function defs with mutable arguments hold a reference to the mutable container such that all invocations access the same changeable container. To get separate mutable default arguments, use: def f(x=None): if x is None: x=[2,3] Emile On 01/21/2014 11:11 AM, Mû wrote: Hi everybody, A friend of mine asked me a question about the following code: [code] def f(x=[2,3]): x.append(1) return x print(f()) print(f()) print(f()) [/code] The results are [2, 3, 1], [2, 3, 1, 1] and [2, 3, 1, 1, 1]. The function acts as if there were a global variable x, but the call of x results in an error (undefined variable). I don't understand why the successive calls of f() don't return the same value: indeed, I thought that [2,3] was the default argument of the function f, thus I expected the three calls of f() to be exactly equivalent. I'm don't know much about python, does anybody have a simple explanation please? -- https://mail.python.org/mailman/listinfo/python-list
Re: ANN: PSF Python Marketing Brochure - Last call for Ad Sponsors
Under Subscription Sponsors in the listing of destinations, I'm going to guess from the grouping that NE should be NL. Emile On 02/11/2014 08:18 AM, M.-A. Lemburg wrote: [Please help spread the word by forwarding to other relevant mailing lists, user groups, etc. world-wide; thanks :-)] ANNOUNCING PSF Python Marketing Brochure - Last call for Ad Sponsors Please support the PSF in providing the Python community with free high quality marketing material to promote Python INTRODUCTION Over the last few years, the Python brochure team has worked on and created a high-quality brochure to help user groups, conferences and companies using Python to promote and spread the word about Python. The brochure will be printed in a first edition of 10,000 copies which the PSF will then distribute to user groups, Python conferences and educational institutions on request and free of charge. With the Python brochure, we hope to reach out to an audience which is not easy to address and convince using electronic and mostly developer oriented media. PREVIEW Please take a look at our preview PDF version of the brochure to see for yourself: http://brochure.getpython.info/preview.pdf SEEKING YOUR HELP The team set out to create and print the brochure without introducing extra costs for the PSF. Our aim is to fully finance the brochure production, printing and shipment to interested parties using money from sponsors. To make this happen, we are seeking your help ! => We have already signed up sponsors for 6 half page ads, but still need another *5 half page ad sponsors* to sign up. => There are also *6 smaller reference entry sponsorships* left to be sold. If you are affiliated with or know a company investing into Python and looking for ways to reach out to a large audience of interested Python users, students, developers - and people in key decision making positions, please reach out to us and help make the project a success. The deadline for ad and reference entry signups is *Feb 28* - in just under three weeks. You can find all the details about the available sponsorship options on this page: http://brochure.getpython.info/sponsorship Orders can be placed directly with the production company, Evenios Publishing on the website. All sponsors will receive a box of about 120 free copies of the brochure as Thank You gift. ORDERING EXTRA COPIES Companies who are interested in receiving extra copies can pre-order additional boxes which will then be printed in addition to the initial 10.000 copy batch: http://brochure.getpython.info/mediadata/subscription-order-procedure It is also possible to donate such extra boxes to educational institutions: http://brochure.getpython.info/mediadata/education-sponsorship If you have special requirements, please contact the team at [email protected] for more information. We're very flexible in addressing your needs. MORE INFORMATION More information on the brochure, the idea behind it, media data and ordering links are available on our project page: http://brochure.getpython.info/ Thanks for your help, -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is the interpreter is returning a 'reference'?
On 02/17/2014 09:00 AM, Nir wrote: k = ['hi','boss'] k ['hi', 'boss'] k= [s.upper for s in k] s.upper is a reference to the method upper of s -- to execute the method add parens -- s.upper() Emile k [, ] Why doesn't the python interpreter just return ['HI, 'BOSS'] ? This isn't a big deal, but I am just curious as to why it does this. -- https://mail.python.org/mailman/listinfo/python-list
Re: find and replace string in binary file
On 03/04/2014 02:44 PM, Chris Angelico wrote: On Wed, Mar 5, 2014 at 12:18 AM, Peter Otten <[email protected]> wrote: loial wrote: How do I read a binary file, find/identify a character string and replace it with another character string and write out to another file? Its the finding of the string in a binary file that I am not clear on. That's not possible. You have to convert either binary to string or string to binary before you can replace. Whatever you choose, you have to know the encoding of the file. If it's actually a binary file (as in, an executable, or an image, or something), then the *file* won't have an encoding, so you'll need to know the encoding of the particular string you want and encode your string to bytes. On 2.7 it's as easy as it sounds without having to think much about encodings and such. I find it mostly just works. emile@paj39:~$ which python /usr/bin/python emile@paj39:~$ python Python 2.7.3 (default, Sep 26 2013, 16:38:10) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> image = open('/usr/bin/python','rb').read() >>> image.find("""Type "help", "copyright", "credits" """) 1491592 >>> image = image[:1491592]+"Echo"+image[1491592+4:] >>> open('/home/emile/pyecho','wb').write(image) >>> emile@paj39:~$ chmod a+x /home/emile/pyecho emile@paj39:~$ /home/emile/pyecho Python 2.7.3 (default, Sep 26 2013, 16:38:10) [GCC 4.7.2] on linux2 Echo "help", "copyright", "credits" or "license" for more information. YMMV, Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Oddity using sorted with key
On 03/11/2014 09:13 AM, Josh English wrote:
I am running into a strange behavior using the sorted function in Python 2.7.
The key parameter is not behaving as the docs say it does:
Here is a snippet of code, simplified from my full program:
#begin code
class Thing(object):
def __init__(self, name):
self.name = name
def __repr__(self):
return "Thing %s" % self.name
stuff = [Thing('a'), Thing('C'), Thing('b'), Thing('2')]
more_stuff = [Thing('d'), Thing('f')]
all_the_stuff = stuff + more_stuff
print list(sorted(all_the_stuff, key=lambda x: x.name.lower))
in this case everything sorts by the same value of the bound method of
name.lower. You could have used "".lower, which has the same value as
x.name.lower, and gotten the same results.
print list(sorted(all_the_stuff, key=lambda x: x.name.lower()))
in this case you're sorting by the lower case value of x.name, which is
what you want.
Emile
# END
The output is:
[Thing d, Thing f, Thing 2, Thing a, Thing b, Thing C]
[Thing 2, Thing a, Thing b, Thing C, Thing d, Thing f]
The second call to sorted works as expected. Just using the method doesn't sort
properly.
Any ideas why I'm seeing two different results? Especially as the correct form
is giving me the wrong results?
Josh English
--
https://mail.python.org/mailman/listinfo/python-list
Re: Significant digits in a float?
On 04/29/2014 01:16 PM, Adam Funk wrote: "A man pitches his tent, walks 1 km south, walks 1 km east, kills a bear, & walks 1 km north, where he's back at his tent. What color is the bear?" ;-) From how many locations on Earth can someone walk one mile south, one mile east, and one mile north and end up at their starting point? Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Significant digits in a float?
On 04/30/2014 11:21 AM, Grant Edwards wrote: On 2014-04-29, emile wrote: On 04/29/2014 01:16 PM, Adam Funk wrote: "A man pitches his tent, walks 1 km south, walks 1 km east, kills a bear, & walks 1 km north, where he's back at his tent. What color is the bear?" ;-) From how many locations on Earth can someone walk one mile south, one mile east, and one mile north and end up at their starting point? I'm pretty sure there are places in London like that. At least that's what it seemed like to somebody from the midwestern US where the streets are layed out on a grid. I was going to bring up London, but as I recall from my brief visit there, I wasn't sure you could go one mile straight in any direction. :) Emile -- https://mail.python.org/mailman/listinfo/python-list
Odd ValueError using float
On an older WinXP SP2 box with python2.6 that's been running this process fine for years, this week we're seeing: > c:\python26\lib\site-packages\fenx\sql_interface.py(144)normalized() -> return val (Pdb) val *** NameError: name 'val' is not defined (Pdb) l 139 try: 140 val = round(float(decval),1) 141 except: 142 import pdb; pdb.set_trace() 143 #val = round(float(int(decval)/10**((decval%100)*100)),1) 144 -> return val 145 146 147 def foodList(reference): 148 # return a list of (code,val) tuples for the ingredients of the foodlist referenced 149 # local internal use only to create sqlFoodListsByID (Pdb) decval '4' (Pdb) len(decval) 1 (Pdb) int(decval) *** ValueError: invalid literal for int() with base 10: '41.7000003' (Pdb) Any ideas? Thanks, Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Odd ValueError using float
On 03/13/2015 03:14 PM, Chris Angelico wrote: On Sat, Mar 14, 2015 at 9:10 AM, emile wrote: (Pdb) decval '4' (Pdb) len(decval) 1 (Pdb) int(decval) *** ValueError: invalid literal for int() with base 10: '41.703' (Pdb) Any ideas? What's type(decval) tell you? I suspect you may have something other than a string, even though it looks like a string in its repr. >sigh< Now it's running again. Up to 20 minutes ago when I posted it continually. Is-it-time-to-go-pick-grapes-yet?-ly y'rs, Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Odd ValueError using float
On 03/13/2015 08:09 PM, Chris Angelico wrote: On Sat, Mar 14, 2015 at 1:33 PM, Paul Rubin wrote: emile writes: *** NameError: name 'val' is not defined (Pdb) l 139 try: 140 val = round(float(decval),1) 141 except: 142 import pdb; pdb.set_trace() If 'float' or 'round' throw an exception, the assignment to 'val' never happens, so 'val' is undefined. Try examining the value of 'decval' in the debugger to see what is making the conversion fail. That's exactly what the OP did :) Trouble is, it didn't help, because it sure looked as if decval was the string '4'. My best guess was - and is - that it's not just a string. We're looking at an SQL interface routine here, so it may be that there's a string subclass that length-limits itself, on the assumption that it's going into a fixed-length database field. It ran almost to completion before generating the error again -- (Pdb) decval '4' (Pdb) type(decval) (Pdb) len(decval) 1 (Pdb) int(decval) *** ValueError: invalid literal for int() with base 10: '41.703' So there's still something amiss. Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Odd ValueError using float
On 03/14/2015 09:08 AM, Peter Otten wrote: emile wrote: On 03/13/2015 08:09 PM, Chris Angelico wrote: On Sat, Mar 14, 2015 at 1:33 PM, Paul Rubin wrote: emile writes: *** NameError: name 'val' is not defined (Pdb) l 139 try: 140 val = round(float(decval),1) 141 except: 142 import pdb; pdb.set_trace() If 'float' or 'round' throw an exception, the assignment to 'val' never happens, so 'val' is undefined. Try examining the value of 'decval' in the debugger to see what is making the conversion fail. That's exactly what the OP did :) Trouble is, it didn't help, because it sure looked as if decval was the string '4'. My best guess was - and is - that it's not just a string. We're looking at an SQL interface routine here, so it may be that there's a string subclass that length-limits itself, on the assumption that it's going into a fixed-length database field. It ran almost to completion before generating the error again -- (Pdb) decval '4' (Pdb) type(decval) (Pdb) len(decval) 1 (Pdb) int(decval) *** ValueError: invalid literal for int() with base 10: '41.703' So there's still something amiss. Why are you checking int(decval) because it sure smells like int should work: (Pdb) "3" when the actual failing expression is round(float(decval),1) ? Try to evaluate the latter in the debugger, and if that gives no clue change 139 try: 140 val = round(float(decval),1) 141 except: 142 import pdb; pdb.set_trace() to just val = round(float(decval), 1) to get a meaningful traceback and post that. I don't get a traceback -- it spews: Fatal Python error: deletion of interned string failed This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. then crashes and I get a Microsoft pop-up that says python.exe has encountered a problem and needs to close. Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Odd ValueError using float
On 03/14/2015 08:52 AM, Chris Angelico wrote:
On Sun, Mar 15, 2015 at 2:28 AM, emile wrote:
It ran almost to completion before generating the error again --
(Pdb) decval
'4'
(Pdb) type(decval)
(Pdb) len(decval)
1
(Pdb) int(decval)
*** ValueError: invalid literal for int() with base 10: '41.703'
So there's still something amiss.
Compare these two lines' outputs:
print("str %d, int %d" % (id(str), id(int)))
print("str %d, int %d" % (id(type("")), id(type(0)))
(Pdb) print("str %d, int %d" % (id(str), id(int)))
str 505366496, int 505399904
(Pdb) print("str %d, int %d" % (id(type("")), id(type(0
str 505366496, int 505399904
Any difference in id would indicate that the names have been shadowed
- seems unlikely, but worth checking. And then, just to be absolutely
sure:
type(decval) is type("")
(Pdb) type(decval) is type("")
True
There is another, and very nasty, possibility. If you're working with
a C extension that has a refcount bug in it, all sorts of bizarre
things can happen - crucial type objects getting garbage collected,
objects getting disposed of and others taking their places, all kinds
of weird and wonderful things. Normally that'll eventually cause a
crash, but who knows...
Here're the imports:
import os, time, re, shutil, subprocess
from fenx.BBxXlate.bbxfile import BBxFile # a pure python module
from fenx import RealPyOdbc2
and of course, pdb when I break for the error condition.
Emile
--
https://mail.python.org/mailman/listinfo/python-list
Re: Odd ValueError using float
On 03/14/2015 11:24 AM, Peter Otten wrote: emile wrote: On 03/14/2015 09:08 AM, Peter Otten wrote: Why are you checking int(decval) because it sure smells like int should work: (Pdb) "3" That's a normal string comparison when decval is a string. This and the ValueError is expected Python behaviour: yes -- but i'd previously shown decval to have a length of 1, and how many things then fit that equation? to get a meaningful traceback and post that. I don't get a traceback -- it spews: Fatal Python error: deletion of interned string failed This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. then crashes and I get a Microsoft pop-up that says python.exe has encountered a problem and needs to close. That does look bad. Most likely an extension written in C corrupts the interpreter or it's even a bug in the interpreter itself. I'm tight on time the rest of the day, but I think I'll next zap all the pyc versions, install a fresh 2.6.x python, and let it recompile. About the only theory I have at the moment to explain the sudden failure after years of non-failure is disk based bit-rot. Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Odd ValueError using float
On 03/15/2015 07:01 AM, Peter Otten wrote:
Probably not helpful, but I can provoke the behaviour you see by toggling
bytes with ctypes, thus simulating a corrupted str object:
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import ctypes
s = "41.703"
ctypes.c_ubyte.from_address(id(s) + 16).value = 1
s
'4'
len(s)
1
float(s)
Traceback (most recent call last):
File "", line 1, in
ValueError: invalid literal for float(): 41.703
int(s)
Traceback (most recent call last):
File "", line 1, in
ValueError: invalid literal for int() with base 10: '41.703'
I dug through the code and ctypes was in the mix. Without discovering
the actual issue, I did manage to work around the issue by replacing:
val = round(float(decval),1)
with
val = round(float("".join([ii if ii=="." else str(int(ii)) for ii in
decval])),1)
Thanks.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Fastest I/O on Python ?
On 07/22/2014 09:06 AM, Orochi wrote:
Is there in any other input/output faster than ("raw_input","input" / "print")
The limitation is with the device -- either the human typing in
responses or the output device rendering the output. If you have the
option to read/write to disk that'd open up additional options.
Otherwise I'm not sure there's much to be gained.
Emile
As I am trying to solve competitive Programs on codechef.com using python i was
wondering if there is any other way to print and scan the inputs fast.
I have seen other people codes and there are using sys library(stdin and
stdout) for I/O.
So I was thinking is there any other way to take input/output besides using
'sys library'.
And also I had doubt about what is the difference between
(raw_input,input/print) and (stdin/stdout)
Thank You.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Question about Pass-by-object-reference?
On 07/22/2014 01:35 PM, Peter Pearson wrote: On Tue, 22 Jul 2014 12:34:51 -0700 (PDT), fl wrote: [snip] But I don't understand the reassign function result: def reassign(list): ... list=[0,1] ... list=[0] reassign(list) print list [0] When you say "def reassign(list)", that means "I'm defining a function to which the caller will pass one object, and within this function I'm going to refer to that object by the name 'list'." Then, when you say "list=[0,1]", that means "Create the object [0,1], and assign to it the name 'list'." At this point, there is no longer any name that refers to the object that the caller passed. You might have thought that "list=[0,1]" would modify the caller-passed object, but that's not what happens. That's not what "=" means. However, if that is the behavior you were after, you can get there. def reassign(mylist): # no reason to shadow the list builtin mylist[:] = [0,1] mylist = [1] reassign(mylist) mylist Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to install Python on a network?
On 07/22/2014 01:49 PM, [email protected] wrote: We are using Python in a large setup. Individual users are running Debian machines. When I want to install/upgrade Python for all users, I really want to do it centrally rather than every user having to upgrade on their own. Many software packages are installed this way. However, I could not figure out any way to do this with Python. How can I do this? This is more a sysadmin than python issue. And, debian itself has python dependencies, so you need to be careful you don't break it. That said, we use a similar setup and have an aptitude repository with approved software that holds the approved source packages users can install. Combining automated user system updating with a sole repository where only your versions are available should do it. Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Why does not pprint work?
On 07/22/2014 02:42 PM, fl wrote: Hi, I read web tutorial at: http://nedbatchelder.com/blog/201308/names_and_values_making_a_game_board.html I enter the example lines of that website: import pprint board = [ [0]*8 ] * 8 pprint(board) pprint is a module name -- you need to invoke the pprint function from within the pprint module: pprint.pprint(board) or alternately, from pprint import pprint pprint(board) or, as I sometime do from pprint import pprint as pp pp(board) Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Why does not pprint work?
On 07/22/2014 03:05 PM, fl wrote: On Tuesday, July 22, 2014 5:51:07 PM UTC-4, emile wrote: On 07/22/2014 02:42 PM, fl wrote: pprint is a module name -- you need to invoke the pprint function from within the pprint module: pprint.pprint(board) Thanks. I am curious about the two pprint. Is it the first pprint the name of the module? The second pprint is the function name? Yes. Then, how can I list all the function of pprint? use the dir builtin: >>> dir (pprint) ['PrettyPrinter', '_StringIO', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '_commajoin', '_id', '_len', '_perfcheck', '_recursion', '_safe_repr', '_sys', '_type', 'isreadable', 'isrecursive', 'pformat', 'pprint', 'saferepr'] And, is there a way to list the variables I create in Python? also dir: >>> dir() ['__builtins__', '__doc__', '__name__', 'board', 'mylist', 'pprint', 'reassign'] Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about Pass-by-object-reference?
On 07/22/2014 03:17 PM, fl wrote: On Tuesday, July 22, 2014 4:46:25 PM UTC-4, emile wrote: On 07/22/2014 01:35 PM, Peter Pearson wrote: def reassign(mylist): # no reason to shadow the list builtin mylist[:] = [0,1] mylist = [1] reassign(mylist) mylist Emile Thanks for your example. I do not find the explanation of [:] on line. It's covered in the tutorial in https://docs.python.org/2/tutorial/introduction.html look for the section on slice notation Could you explain it to me, or where can I find it on line? If you haven't already, you should work your way through the full tutorial if for no other reason that to be familiar with content others find beginners should be introduced to. https://docs.python.org/2/tutorial/index.html Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about Pass-by-object-reference?
On 07/22/2014 03:31 PM, fl wrote: I have a new question on the code. When I run it in a file on PythonWin, 'mylist' does not echo anything on the screen. While I enter the command line by line, 'mylist' shows the result: mylist [0, 1] What mechanism is involved? As a convenience, the interactive prompt environment will display the value of a variable when entered on its own. In scripts, you'd usually want to use print. Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about Pass-by-object-reference?
On 07/22/2014 04:00 PM, fl wrote: On Tuesday, July 22, 2014 4:35:33 PM UTC-4, Peter Pearson wrote: On Tue, 22 Jul 2014 12:34:51 -0700 (PDT), fl wrote: When you say "def reassign(list)", that means "I'm defining a function to which the caller will pass one object, and within this function I'm going to refer to that object by the name 'list'." Then, when you say "list=[0,1]", that means "Create the object [0,1], The above is what rebind? see below I cite. exactly. assigning to a variable within a function makes that variable local to the function; assigning to the contents (as with [:]) changes the contents, but not the container variable, and as the container element was passed in you'll see the changed item outside the function. Emile and assign to it the name 'list'." At this point, there is no longer any name that refers to the object that the caller passed. Here is I find on-line about "Arguments are passed by assignment." http://stackoverflow.com/questions/986006/python-how-do-i-pass-a-variable-by-reference "If you pass a mutable object into a method, the method gets a reference to that same object and you can mutate it to your heart's delight, but if you rebind the reference in the method, the outer scope will know nothing about it, and after you're done, the outer reference will still point at the original object." Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: Dynamically swapping between two algorithms
Add a timing harness and use a test interval (N) and call LARGE every Nth loop until LARGE's timing is better than the prior SHORT's run. Emile On 09/23/2014 07:48 AM, Steven D'Aprano wrote: I have a certain calculation which can be performed two radically different ways. With the first algorithm, let's call it SHORT, performance is very fast for small values of the argument, but terrible for large values. For the second algorithm, LARGE, performance is quite poor for small values, but excellent for large values. To add to the complexity, I perform this calculation repeatedly, in a loop: value = 1 while True: x = SHORT(value) # Or should I use LARGE? Decisions, decisions... process(x) value += some_increment() if condition: break Luckily, the value never gets smaller. So if I could somehow determine a cut-over point, CUTOFF, I might write my loop like this: value = 1 while True: f = SHORT if value < CUTOFF else LARGE x = f(value) process(x) value += some_increment() if condition: break alas, the CUTOVER point is likely to be machine-dependent. Take it as a given that inserting a fixed CUTOVER point into the source code (say, ``CUTOVER = 123456``) is not likely to be very effective, and dynamically calculating it at import time is impractical. *If* Python was a different language, I would spawn two threads, one using SHORT and the other using LARGE, then which ever completes first, I'd just kill the other. Alas, this won't work because (1) the GIL and (2) you cannot forcibly kill threads, only ask them to die and hope they listen. I am seeking other ideas for dynamically swapping between the two algorithms, based on runtime information. Any thoughts? (1) I can't tell in advance how many loops I will make. (2) Both SHORT and LARGE get slower as the size of their argument increases. This is unavoidable due to the nature of the problem. (3) SHORT starts off relatively speedy, significantly faster than LARGE for the first few tens of thousands of loops. I'm not talking about trivial micro-optimizations here, I'm talking about the difference between 0.1 second for SHORT versus 10 seconds for LARGE. (4) But as the size of the argument increases, SHORT suffers catastrophic quadratic slowdown, while LARGE slows down only linearly. (Give or take.) (5) Consequently, by the time I reach a few million loops, the difference is now between (say) 5 minutes for LARGE versus 15 hours for SHORT. (6) There is no single algorithm which performs acceptably across the entire range of values I'm expecting to process in practice. (7) Leaving the choice up to the caller is not an option. I am the caller. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to select every other line from a text file?
On 10/13/2014 11:02 AM, Mark Lawrence wrote: Why bother to initialise a counter when you can get the enumerate function to do all the work for you? I see it as a question of addressing the audience. Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: How to select every other line from a text file?
On 10/13/2014 12:12 PM, Tim Chase wrote: You mean like offset = 0 # or 1 if you prefer for line in itertools.islice(source_iter, offset, None, 2): do_something(line) I certainly did. Learning the python standard library is different from learning python and each in its own time. Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you feel bad because of the Python docs?
On 02/26/2013 11:00 AM, nn wrote: > What it could have is better searching capability and a way to see > more examples. Examples would clutter the documentation so maybe they > should be collapsible, but you can never have enough examples. A good resource (although only covering up to v2.3) is effbot's guide to the standard library available at http://effbot.org/zone/librarybook-index.htm It's pretty much _all_ examples. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Input wont work with if statement if it has a space
On 03/05/2013 03:33 PM, eli m wrote:
On Tuesday, March 5, 2013 3:31:13 PM UTC-8, eli m wrote:
Hi guys, i have a program like this: (A lot of code is not included)
run = 0
while run == 0:
function = raw_input("Type in a function:")
if function == "Example":
whenever function isn't _exactly_ "Example" the else clause executes.
If you want to catch forms of example you might try:
if function.strip().upper() == "EXAMPLE":
Emile
print ("Hello World!")
else:
print ("blah blah blah")
The problem is that whenever i type in example with a space after it then it
prints the else statement.
My question is, how do i get it to except input with spaces?
oops i meant function = raw_input("Type in a function:")
--
http://mail.python.org/mailman/listinfo/python-list
Re: An error when i switched from python v2.6.6 => v3.2.3
On 03/08/2013 12:54 PM, [email protected] wrote: Τη Παρασκευή, 8 Μαρτίου 2013 8:54:15 μ.μ. UTC+2, ο χρήστης Steven D'Aprano έγραψε: -c ''; rm -rf /; oops.py Please don't tell the newbies to destroy their system, no matter how tempting it might be. What that "-c ''" options i keep seeing in the attempts to pass bogus info in my 'page' variable? And hows oops.py relevant? Such file doesnt nto exist in my webssever. You're certainly right about that -- particularly by the time it's attempted. :) Emile -- http://mail.python.org/mailman/listinfo/python-list
os.path.isfile with *.tar.gz
Hello All,
I'm new to Python and it looks like people that post here do get
a good answer back so I figured I'd try my luck.
I'm trying to check a directory to see if there is a file that has the
name "startOfString" + some version number + "inst.tar.gz"
(component-8.3.16-inst.tar.gz) The version number will change quite
frequently so I just want to check if there is a file with that format
name.
I have tried variations of: os.path.isfile( os.path.join("C:\\temp\\",
"rqp-win32-app", "*.tar.gz"))
but nothing seem to work. Does anyone have suggestions on how I could
get this to work?
Thanks in advance for the help,
Emile
This message may contain privileged and/or confidential information. If
you have received this e-mail in error or are not the intended recipient, you
may not use, copy, disseminate or distribute it; do not open any attachments,
delete it immediately from your system and notify the sender promptly by e-mail
that you have done so. Thank you.
--
http://mail.python.org/mailman/listinfo/python-list
Subject line with smtplib.sendmail()
Hey, I'm trying to send mail from my server to my machine with test results. I can send the email no problem however, the email doesn't contain a "recipient list" or a "subject line". I was wondering how would I go about getting the information on the actual "To" and "Subject" lines so that I know to whom the email was sent and the subject line without opening the email? Thanks in advance for the help. Emile Boudreau This message may contain privileged and/or confidential information. If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Subject line with smtplib.sendmail()
Thanks for the reply. When I use the instruction from that list this is the email I receive. I'm using Outlook. [EMAIL PROTECTED] To: -- From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Hello! This Still DOESN't Work It's just adding the "From" "To" "Subject" in the message itself. I want to have each field at the correct place and then just the msg in the body. Any Help?? Thanks Emile Boudreau -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Fredrik Lundh Sent: Tuesday, March 20, 2007 11:08 AM To: [email protected] Subject: Re: Subject line with smtplib.sendmail() Boudreau, Emile wrote: > I'm trying to send mail from my server to my machine with test > results. I can send the email no problem however, the email doesn't > contain a "recipient list" or a "subject line". I was wondering how > would I go about getting the information on the actual "To" and > "Subject" lines so that I know to whom the email was sent and the > subject line without opening the email? you have to add the headers yourself. see the example in the library reference, or this FAQ entry: http://effbot.org/pyfaq/how-do-i-send-mail-from-a-python-script -- http://mail.python.org/mailman/listinfo/python-list This message may contain privileged and/or confidential information. If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Subject line with smtplib.sendmail()
Sorry folks. Scrape the last one that I sent. I noticed that it sends the email perfectly if the code is not in any of my methods but the second I insert it into a method I get the ugly email that I described in my last email. Does anyone know how I can get this code in my method so that I have access to all the variables I have? thanks Emile Boudreau -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Boudreau, Emile Sent: Tuesday, March 20, 2007 1:51 PM To: [email protected] Subject: RE: Subject line with smtplib.sendmail() Thanks for the reply. When I use the instruction from that list this is the email I receive. I'm using Outlook. [EMAIL PROTECTED] To: -- From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Hello! This Still DOESN't Work It's just adding the "From" "To" "Subject" in the message itself. I want to have each field at the correct place and then just the msg in the body. Any Help?? Thanks Emile Boudreau -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Fredrik Lundh Sent: Tuesday, March 20, 2007 11:08 AM To: [email protected] Subject: Re: Subject line with smtplib.sendmail() Boudreau, Emile wrote: > I'm trying to send mail from my server to my machine with test > results. I can send the email no problem however, the email doesn't > contain a "recipient list" or a "subject line". I was wondering how > would I go about getting the information on the actual "To" and > "Subject" lines so that I know to whom the email was sent and the > subject line without opening the email? you have to add the headers yourself. see the example in the library reference, or this FAQ entry: http://effbot.org/pyfaq/how-do-i-send-mail-from-a-python-script -- http://mail.python.org/mailman/listinfo/python-list This message may contain privileged and/or confidential information. If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so. Thank you. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
2 Command prompt at the same time
Hello, I have two batch files and I'm trying to run them in parallel. I haven't been able to find any information on how to make python open 2 command prompt and then make each prompt run one of the batch files. Can anyone point me in the right direction? Thanks, Emile Boudreau This message may contain privileged and/or confidential information. If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Two Command prompts in parallels
Hello, I have two batch files and I'm trying to run them in parallel. I haven't been able to find any information on how to make python open 2 command prompt and then make each prompt run one of the batch files. Can anyone point me in the right direction? Thanks, Emile Boudreau This message may contain privileged and/or confidential information. If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Sending emails to 3 addresses....
Hello all, I'm trying to send a results email to 3 people. For some
reason only the first person in the list will receive the email but in
the received email it shows the 3 addresses. Here is my code, can
someone show me where I'm going wrong?? Thanks
sendMail('this is the subject line', 'the results: 71 fails, 229 pass,
300 total.', '[EMAIL PROTECTED], [EMAIL PROTECTED],
[EMAIL PROTECTED]')
def sendMail(subject, body, TO, FROM="[EMAIL PROTECTED]"):
print TO
HOST = "exchange.mycompany.com"
BODY = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % subject,
"",
body
), "\r\n")
server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO], BODY)
server.quit()
Emile Boudreau
This message may contain privileged and/or confidential information. If
you have received this e-mail in error or are not the intended recipient, you
may not use, copy, disseminate or distribute it; do not open any attachments,
delete it immediately from your system and notify the sender promptly by e-mail
that you have done so. Thank you.
--
http://mail.python.org/mailman/listinfo/python-list
RE: Sending emails to 3 addresses....
Thanks so much I would of never found that out. Problem SOLVED Emile Boudreau -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tim Williams Sent: Friday, March 30, 2007 9:12 AM To: Boudreau, Emile Cc: [email protected] Subject: Re: Sending emails to 3 addresses On 30/03/07, Tim Williams <[EMAIL PROTECTED]> wrote: Emile, (slight change to my original reply) You are passing the TO addresses as 3 addresses in a single string. [TO] results in a list containing a single string - not a list containing 3 individual addresses. You need to either pass the addresses to the function as a list containing the 3 addresses as individual strings, and remove the conversion to a list at sending time. Or change [TO] to TO.split(',') HTH :) This message may contain privileged and/or confidential information. If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Problem with filter()
Hey all,
So I'm trying to filter a list with the built-in function
filter(). My list looks something like this:
['logs', 'rqp-8.2.104.0.dep', 'rqp-8.2.93.0.dep',
'rqp-win32-app-8.2.96.0-inst.tar.gz',
'rqp-win32-app-8.2.96.0-inst.tar.gz']
Calling filter like this: compFiles = filter(is_Dev, compFiles)
compFiles is my list and is_dev is the following
def is_Dev(stringy):
print stringy
stringx = stringy.split('-')
if stringx[1] == r'win32':
if stringx[2] == r'app':
if stringx[4] == r'dev.tar.gz':
return 1
For some reason I only get 'logs' printed when is_Dev is called. (ie.
It's only going through is_dev once)
Does anyone see something wrong that I'm not seeing??
Thanks,
Emile Boudreau
This message may contain privileged and/or confidential information. If
you have received this e-mail in error or are not the intended recipient, you
may not use, copy, disseminate or distribute it; do not open any attachments,
delete it immediately from your system and notify the sender promptly by e-mail
that you have done so. Thank you.
--
http://mail.python.org/mailman/listinfo/python-list
RE: Problem with filter()
Sorry folks my mistake def is_dev should be:
def is_Dev(stringy):
stringx = stringy.split('-')
if stringx[0] == '':
if stringx[1] == r'win32':
if stringx[2] == r'app':
if stringx[4] == r'dev.tar.gz':
return 1
But now the results of the filter is an empty list and i know it
shouldn't be.
Emile Boudreau
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Boudreau, Emile
Sent: Tuesday, April 03, 2007 10:52 AM
To: [email protected]
Subject: Problem with filter()
Hey all,
So I'm trying to filter a list with the built-in function
filter(). My list looks something like this:
['logs', 'rqp-8.2.104.0.dep', 'rqp-8.2.93.0.dep',
'rqp-win32-app-8.2.96.0-inst.tar.gz',
'rqp-win32-app-8.2.96.0-inst.tar.gz']
Calling filter like this: compFiles = filter(is_Dev, compFiles)
compFiles is my list and is_dev is the following
def is_Dev(stringy):
print stringy
stringx = stringy.split('-')
if stringx[1] == r'win32':
if stringx[2] == r'app':
if stringx[4] == r'dev.tar.gz':
return 1
For some reason I only get 'logs' printed when is_Dev is called. (ie.
It's only going through is_dev once)
Does anyone see something wrong that I'm not seeing??
Thanks,
Emile Boudreau
This message may contain privileged and/or confidential
information. If you have received this e-mail in error or are not the
intended recipient, you may not use, copy, disseminate or distribute it;
do not open any attachments, delete it immediately from your system and
notify the sender promptly by e-mail that you have done so. Thank you.
--
http://mail.python.org/mailman/listinfo/python-list
Extracting a file from a tarball
I am trying to extract one file from a tarball, without success. This is
the code I'm using to open the tarball and extract the file:
tar = tarfile.open(component+'-win32-app-'+bestVersion+'-dev.tar.gz',
'r')
extractedFile = tar.extractfile('symbols.xml')
And this is my error:
Traceback (most recent call last):
File "C:\CognosInstalls\AutoTest\PollDir.py", line 121, in
main()
File "C:\CognosInstalls\AutoTest\PollDir.py", line 119, in main
extract('c:\\', 'I:\\daily\\'+components[i], components[i])
File "C:\CognosInstalls\AutoTest\PollDir.py", line 27, in extract
filelike = tar.extractfile('symbols.xml')
File "C:\Python25\lib\tarfile.py", line 1488, in extract
tarinfo = self.getmember(member)
File "C:\Python25\lib\tarfile.py", line 1171, in getmember
raise KeyError("filename %r not found" % name)
KeyError: "filename 'symbols.xml' not found"
I know that the tarball contants this file "symbols.xml" but I don't
understand why it's not extracting it. Any help will be greatly
appreciated.
Thanks,
Emile Boudreau
This message may contain privileged and/or confidential information. If
you have received this e-mail in error or are not the intended recipient, you
may not use, copy, disseminate or distribute it; do not open any attachments,
delete it immediately from your system and notify the sender promptly by e-mail
that you have done so. Thank you.
--
http://mail.python.org/mailman/listinfo/python-list
RE: Extracting a file from a tarball
Your hint of checking "tar.getnames()" was exatly what I needed. It returns the path to where the file will be extracted (ie. Src/ver/qfw/symbols.xml). After knowing this fact it was quite simple to extract the file. Thanks, problem solved!!! Emile Boudreau x5754 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Carsten Haese Sent: Tuesday, April 03, 2007 1:42 PM To: [email protected] Subject: Re: Extracting a file from a tarball On Tue, 2007-04-03 at 13:26 -0400, Boudreau, Emile wrote: > I am trying to extract one file from a tarball, without success. This > is the code I'm using to open the tarball and extract the file: > > tar = tarfile.open(component+'-win32-app-'+bestVersion+'-dev.tar.gz', > 'r') > extractedFile = tar.extractfile('symbols.xml') > > And this is my error: > > Traceback (most recent call last): > File "C:\CognosInstalls\AutoTest\PollDir.py", line 121, in > main() > File "C:\CognosInstalls\AutoTest\PollDir.py", line 119, in main > extract('c:\\', 'I:\\daily\\'+components[i], components[i]) > File "C:\CognosInstalls\AutoTest\PollDir.py", line 27, in extract > filelike = tar.extractfile('symbols.xml') > File "C:\Python25\lib\tarfile.py", line 1488, in extract > tarinfo = self.getmember(member) > File "C:\Python25\lib\tarfile.py", line 1171, in getmember > raise KeyError("filename %r not found" % name) > KeyError: "filename 'symbols.xml' not found" > > I know that the tarball contants this file "symbols.xml" What does tar.getnames() return? -Carsten -- http://mail.python.org/mailman/listinfo/python-list This message may contain privileged and/or confidential information. If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Using/finding ODBC and DBI
Hello all, I'm trying to use ODBC and DBI but I don't seem to have the right files on my system. I have looked around and I can't find what I'm looking for. From the information I have been able to find these are not part of the standard python library. True?? Where can I find the modules that I'm missing to be able to import the modules correctly and run my script? Thanks, Here is the code that I'm using. import odbc, dbi Query = "select jobs.trakkerid, fixes.change as change, from jobs, fixes where trakkerid <> 'na' and trakkerid <> '' and jobs.job = fixes.job and fixes.change = 28339 order by change desc" db = odbc.odbc( "UDAP4" ) cursor = db.cursor() cursor.execute( Query ) Emile Boudreau x5754 This message may contain privileged and/or confidential information. If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
pylint 0.17.0 and astng 0.18.0 release
Hello, we are glad to announce the release of pylint 0.17.0 http://www.logilab.org/project/pylint/0.17.0 which is based on a major refactoring of astng (0.18.0) http://www.logilab.org/project/logilab-astng/0.18.0 . For python 2.5, pylint will now use python's _ast module which is much faster than the older compiler.ast module. See the ChangeLog files for more detailed information and our blogentry http://www.logilab.org/blogentry/8554 explaining how we support both compiler and _ast. -- Emile Anclin http://www.logilab.fr/ http://www.logilab.org/ Informatique scientifique & et gestion de connaissances -- http://mail.python.org/mailman/listinfo/python-list
Re: Conditional decoration
On 6/18/2012 3:16 PM Roy Smith said... Is there any way to conditionally apply a decorator to a function? For example, in django, I want to be able to control, via a run-time config flag, if a view gets decorated with @login_required(). @login_required() def my_view(request): pass class myDecorator(object): def __init__(self, f): self.f = f def __call__(self): print "Entering", self.f.__name__ self.f() print "Exited", self.f.__name__ def null(a): return a #if condition: myDecorator = null @myDecorator def aFunction(): print "aFunction running" aFunction() Cobbled together from http://www.chrisevans3d.com/pub_blog/?p=530 and http://stackoverflow.com/questions/3687046/python-sphinx-autodoc-and-decorated-members HTH Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: emded revision control in Python application?
On 6/22/2012 8:58 AM duncan smith said... Hello, I have an application that would benefit from collaborative working. Over time users construct a "data environment" which is a number of files in JSON format contained in a few directories You don't say what your target platform is, but on linux I've done some testing with python-fuse that allows interception on file access to take whatever actions you like, in your case archive prior upon write. Might be worth a look. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: emded revision control in Python application?
On 6/22/2012 11:19 AM duncan smith said... On 22/06/12 17:42, Emile van Sebille wrote: On 6/22/2012 8:58 AM duncan smith said... Hello, I have an application that would benefit from collaborative working. Over time users construct a "data environment" which is a number of files in JSON format contained in a few directories So, will the users modify their local environment and you'd push the revisions to a known location for redistribution? How might peer-to-peer work? How would you know which peers get the change, or would all peers get the change? I've been working with rpyc (in as much spare time as I can manage) on some similar sounding issues and am now settling on a central system which provides convenient administration and potential relaying or pulling. See http://rpyc.sourceforge.net/ I just tested my in-process development status and find 64 remote machines up and 5 non-responsive which in my case are likely machines that are not yet configured properly. As this has been on the back burner the past two months I'm pleased with how it's fared in the face of neglect. At least with rpyc (which does have a low learning curve) you'll be fully in python. Emile You don't say what your target platform is, but on linux I've done some testing with python-fuse that allows interception on file access to take whatever actions you like, in your case archive prior upon write. Might be worth a look. Emile I develop on Linux, but most users would be running some flavour of Windows. Initially I'd like to get something up and running that would allow me to collaborate from an Ubuntu box at home with someone using a Windows machine (not sure which version) in an office at the University of Manchester. The most likely end users would (probably) be running Windows machines on a local network with no internet access. I expect it would generally be possible to have an always-on server, but I'm also thinking about peer to peer style communication (information might not always be completely available, but it's better than being totally unaware of changes being made by others). I don't have much experience getting applications to communicate across a network, particularly in a reasonably secure fashion. Someone I know also suggested RabbitMQ. Any pointers that help me to reduce the options to a manageable number of candidates will be appreciated. A shallow learning curve would also be good (given that ATM this is an idea I want to try out rather than paid work). I am looking at fuse at the moment. Thanks. Duncan -- http://mail.python.org/mailman/listinfo/python-list
Re: Which way is best to execute a Python script in Excel?
On 7/5/2012 12:22 AM Maurizio Spadaccino said...
Hi all
I'm new to Python but soon after a few days of studying its features I
find it my favourite mean of programming scripts to allow for data
storing and mining. My idea would be to inplement python scripts from
inside an excel sheet that would store and fetch data from a Mysql
database.
Look again at the com interface -- I've created excel commands
implemented entirely in python this way and it will do everything you're
looking for. Just start with some of the examples and extend from there.
See http://oreilly.com/catalog/pythonwin32/chapter/ch12.html
I did this ten years ago so things have likely changed, but the bits of
the python script that set up com then looked like this:
class fenxUtilities:
_public_methods_ = [ 'FirstPartInsp' ]
_reg_progid_ = "fenxDCom.Util"
_reg_clsid_ = "{3EAD7AB4-2978-4360-8F7D-33FB36E9E146}"
def FirstPartInsp(self,nomDiam, numFlutes, nomOAL, nomLOC):
return EMSpecs(nomDiam, numFlutes, nomOAL, nomLOC).retvals
if __name__=='__main__':
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(fenxUtilities)
HTH,
Emile
So i need the script to be launched, say, by pressing a button
in excel and, for instance, retrieve immediately data from the mysql
table. For what I found in the net, it seems there are three ways to
control python from excel:
1) run my python script via shell using the Run command in VBA, which
seems to me the easiest (but maybe slower?) way;
2) creating a COM server, for which I need more training since it doesnt
appear that easy;
3) via Microsoft Script Control, for which I saw some example around
where It looks like I can 'simulate' a python shell via the
'executeStatement' command.
What would you suggest would be the more performing way to achieve my
goals as described above?
Thanks for you help
Maurizio
--
Maurizio
www.mauriziospadaccino.com <http://www.mauriziospadaccino.com>
---
If you can avoid printing this e-mail, you are only doing good for our
planet.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Which way is best to execute a Python script in Excel?
On 7/6/2012 1:31 AM Maurizio Spadaccino said...
Could you provide me a more detailed 'how-to' tutorial on implementing a VBA
macro that calls a script or a function from python, or tell me where on the
web I can find it? The OReilly chapter seems a bit hard for me at this stage?
I'm not going to write a how-to, but the relevant bits from the VBA code
look like this:
Set fpiUtils = CreateObject("fenxDCom.Util")
response = fpiUtils.FirstPartInsp(nomDiam, numFlutes, nomOAL, nomLOC)
I dont know, for example, where i should tell the macro where to locate the
script...
Registering the com server does that for you (the __name__ == __main__
part of the python script)
Again, get one of the examples working and move out from there.
Emile
--
http://mail.python.org/mailman/listinfo/python-list
Re: Which way is best to execute a Python script in Excel?
On 7/7/2012 2:05 AM Maurizio Spadaccino said...
Thanks again Emile, I'll try out some examples. I found this one:
http://showmedo.com/videotutorials/video?name=2190050&fromSeriesID=219
quite enlightning.
One last doubt is: say the python code gets used by more Excel Users (different
pc), can I include in some way a dinamic generation of the id in order to allow
each pc to register is own COM server or do I have to hard code the id on each
machine specifically?
Here's how to generate an ID, but it's likely not to occur on other
machines.
>>> import pythoncom; print pythoncom.CreateGuid()
{CE571F2A-6BD8-4A8D-9482-4EC02FAC171E}
There's an interesting perspective on uniqueness of guid's at
http://betterexplained.com/articles/the-quick-guide-to-guids/
So, create it once and hardcode it in. If you provide new features in a
subsequent version you may want to issue a new guid, particularly to
develop a new version while still running the old on the same machine.
Each user will then need to have python and pythonwin installed, then
run your com server to execute the com server registration piece in the
"if __name__ == '__main__'" part of things.
Emile
--
http://mail.python.org/mailman/listinfo/python-list
Re: select module missing/corrupt
On 7/7/2012 5:03 AM John Pote said... We are using a virtual web server running some version of Unix. It has Python versions 2.4,2.6 and 3.1 pre-installed. (BTW the intention is to use Python for a CGI script.) When my script imports subprocess I get the traceback File "/usr/lib/python2.6/subprocess.py", line 427, in import select ImportError: No module named select On searching the Python installation I found what I presume is the select module library file /usr/lib/python2.6/lib-dynload/select_failed.so whereas in the 2.4 installation the file is /usr/lib/python2.4/lib-dynload/select.so and subprocess imports OK. Anyone know why the version 2.6 select .so file should be renamed select_failed.so and so not able to be imported? When python builds, modules that don't build cleanly get renamed [module]_failed. See http://mail.python.org/pipermail/python-dev/2002-March/020568.html for more info. Emile Of interest the 3.1 installation also has the select module file re-named select_failed.so. Any help appreciated, Regards, John Pote --- Posted via news://freenews.netfront.net/ - Complaints to [email protected] --- -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On 7/9/2012 2:22 PM Peter said... One of my favourite questions when interviewing - and it was 100% reliable :-) - "what are your hobbies?" If the answer included programming then they were hired, if not, then they went to the "B" list. In my experience, anybody who is really interested in programming will have it as a hobby (and is keen to learn even if they don't currently have the knowledge you require) - otherwise it is "just a job". Every job has a learning curve - whether it is just the particular domain or even a new language, the individual who sees programming as more "than a job" will come up to speed much faster and be more productive in both the short and long term. Every programmer I have ever hired using this criteria worked out well. Hence the age bias. Personally, I'm quite happy now that I've divorced my hobby from my career. And my family likes me better too. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: What's wrong with this code?
On 7/23/2012 7:50 AM Stone Li said... I'm totally confused by this code: Code: a = None b = None c = None d = None x = [[a,b], [c,d]] e,f = x[1] print e,f This prints the first None,None c = 1 d = 2 print e,f And nothing has happened to e or f, so this is the second None,None Why do you expect 1,2? Emile e = 1 f = 2 print c,d Output: None None None None 1 2 I'm expecting the code as: None None 1 2 1 2 What's wrong? And this question made my GUI program totally out of control. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Outlook, sendinf an image in the body of email
On 7/23/2012 11:33 AM [email protected] said... I tried something similar to the example at http://stackoverflow.com/questions/4312687/how-to-embed-images-in-email . Problem is, this line is not understood: mail.BodyFormat = OlBodyFormat.olFormatHTML If I read the example properly, this is bvisual basic and should result in some form of visual basic error (possibly library related) if anything and not a python traceback. Emile Traceback (most recent call last): ... appt.BodyFormat = OlBodyFormat.olFormatHTML NameError: name 'OlBodyFormat' is not defined Bruce -- http://mail.python.org/mailman/listinfo/python-list
Re: Generating valid identifiers
On 7/26/2012 5:26 AM Laszlo Nagy said... I have a program that creates various database objects in PostgreSQL. There is a DOM, and for each element in the DOM, a database object is created (schema, table, field, index and tablespace). I do not want this program to generate very long identifiers. It would increase SQL parsing time, and don't look good. Let's just say that the limit should be 32 characters. But I also want to recognize the identifiers when I look at their modified/truncated names. I had a similar problem with one customer where their legacy green screen app allowed only 40 characters max for the product description, but the marketing description lengths routinely ran out to 75 or so characters. In that situation I reviewed the source marketing descriptions and prepped a utility to translate common longer words or phrases to one of a selection of shortened abbreviations. I then cycled through best fitting substitutions to get as close as reasonable to the 40 character limit which generally resulted in recognizable descriptions in the legacy environment that matched by being directly derived from the longer marketing names. YMMV, Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Error
On 7/29/2012 5:30 AM [email protected] said... On Sunday, July 29, 2012 2:57:18 PM UTC+5:30, (unknown) wrote: Dear Group, I was trying to convert the list to a set, with the following code: set1=set(list1) Thanks for the answer. But my list does not contain another list that is the issue. Intriguing. Thinking what to do. Now you need to identify the type of the object that is causing python to misreport the unhashable type causing the error as the error you're getting says list and you say there isn't one. So, now we have a python bug. >>> set ([1,2,3]) set([1, 2, 3]) >>> set ([1,2,[]]) Traceback (most recent call last): File "", line 1, in TypeError: unhashable type: 'list' >>> set ([1,2,{}]) Traceback (most recent call last): File "", line 1, in TypeError: unhashable type: 'dict' > the code was running fine, but all on a sudden started to give the following error, > > > > set1=set(list1) > > TypeError: unhashable type: 'list' Try adding the following: for ii in list1: try: set([ii]) except: print "this causes an error type (val): %s (%s)" (type(ii),ii) Either it's a python bug or there really is a list in there. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python a commercial proposition ?
On 7/29/2012 5:12 PM Rodrick Brown said... Until the GIL is fixed I doubt anyone will seriously look at Python as an option for large enterprise standalone application development. See openERP -- http://www.openerp.com/ -- they've been actively converting SAP accounts and have recently absorbed a couple SAP resellers. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Linux shell to python
On 7/30/2012 3:56 PM Dan Stromberg said... On Mon, Jul 30, 2012 at 9:26 PM, Barry Scott And of course you can write list comprehensions on as many lines as it take to make the code maintainable. Sigh, and I'm also not keen on multi-line list comprehensions, specifically because I think they tend to make less readable code. It also becomes a mess when you need to insert print statements to get some visibility into what's going on. I tend to write long one-liners then convert them to loops the first time I need to see what's going on. Premature optimization otherwise. :) Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for a neat solution to a nested loop problem
On 8/6/2012 10:14 AM Tom P said... On 08/06/2012 06:18 PM, Nobody wrote: On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: consider a nested loop algorithm - for i in range(100): for j in range(100): do_something(i,j) Now, suppose I don't want to use i = 0 and j = 0 as initial values, but some other values i = N and j = M, and I want to iterate through all 10,000 values in sequence - is there a neat python-like way to this? for i in range(N,N+100): for j in range(M,M+100): do_something(i,j) Or did you mean something else? no, I meant something else .. j runs through range(M, 100) and then range(0,M), and i runs through range(N,100) and then range(0,N) .. apologies if I didn't make that clear enough. for i in range(N,N+100): for j in range(M,M+100): do_something(i % 100 ,j % 100) Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for a neat solution to a nested loop problem
On 8/6/2012 12:22 PM Grant Edwards said... On 2012-08-06, Tom P wrote: ah, that looks good - I guess it works in 2.x as well? I don't know. Let me test that for you... Yes, it works in 2.x as well. :) And from the docs, all the way back to 2.3! 9.7. itertools Functions creating iterators for efficient looping New in version 2.3. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: [newbie] String to binary conversion
On 8/6/2012 1:46 PM Mok-Kong Shen said...
If I have a string "abcd" then, with 8-bit encoding of each character,
there is a corresponding 32-bit binary integer. How could I best
obtain that integer and from that integer backwards again obtain the
original string? Thanks in advance.
It's easy to write one:
def str2val(str,_val=0):
if len(str)>1: return str2val(str[1:],256*_val+ord(str[0]))
return 256*_val+ord(str[0])
def val2str(val,_str=""):
if val>256: return val2str(int(val/256),_str)+chr(val%256)
return _str+chr(val)
print str2val("abcd")
print val2str(str2val("abcd"))
print val2str(str2val("good"))
print val2str(str2val("longer"))
print val2str(str2val("verymuchlonger"))
Flavor to taste.
Emile
--
http://mail.python.org/mailman/listinfo/python-list
Re: Running Python web apps on shared ASO servers?
On 8/16/2012 7:01 AM Gilles said... On Sun, 12 Aug 2012 02:03:33 +0200, Gilles wrote: Does it mean that ASO only supports writing Python web apps as long-running processes (CGI, FCGI, WSGI, SCGI) instead of embedded Python à la PHP? I need to get the big picture about the different solutions to run a Python web application. From what I read, it seems like this is the way things involved over the years: CGI : original method. Slow because the server has to spawn a new process to run the interpreter + script every time a script is run. mod_python : Apache module alternative to CGI. The interpreter is loaded once, and running a script means just handling the script mod_wsgi : mod_python is no longer developped, and mod_wsgi is its new reincarnation FastCGI and SCGI: Faster alternativees to CGI; Run as independent programs, and communicate with the web server through either a Unix socket (located on the same host) or a TCP socket (remote host) Is this correct? Thank you. I'm sure there's no single correct answer to this. Consider (python 2.6]: emile@paj39:~$ mkdir web emile@paj39:~$ cd web emile@paj39:~/web$ cat > test.html hello from test.html emile@paj39:~/web$ python -m SimpleHTTPServer Then browse to localhost:8000/test.html Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7 import socket urllib fails to load, module not found
On 8/17/2012 12:20 PM [email protected] said... Just installed python 2.7 and using with web2py. When running python from command line to bring up web2py server, get errors that python socket and urllib modules cannot be found, can't be loaded. This is not a web2py issue. So, on my system I get: ActivePython 2.7.0.2 (ActiveState Software Inc.) based on Python 2.7 (r27:82500, Aug 23 2010, 17:18:21) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib >>> import socket >>> What does your system show? Emile No other python versions are on the my machine. Pythonpath has the requisite folders identified. Would appreciate any insights as to what may be happening. thanks in advance -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7 import socket urllib fails to load, module not found
On 8/17/2012 1:41 PM [email protected] said... From cmd prompt - I get this: Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. import urllib Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\urllib.py", line 26, in import socket File "C:\Python27\lib\socket.py", line 47, in import _socket ImportError: DLL load failed: The specified module could not be found I also get that if I attempt to import socket. NOTE this does not happen when I'm in the pythonwin IDE. So, try the following in both environments: import sys for ii in sys.path: print ii You'll likely find diffferences between the two. In the pythonwin environment, try: import socket print socket.__file__ Chances are the __file__'s directory isn't in the command line's sys.path. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7 import socket urllib fails to load, module not found
On 8/17/2012 2:22 PM [email protected] said... Done - tail end of the python path had a missing bit...gr... thanks so much Well it's bizarre - now it doesn't. did an import sys from within interpreter, then did import socket. Worked the first time. Restarted and it happened again. The sys.path outputs are identical. The print socket.__file__ reveals a file that is in the sys.path...g. Next, I'd check for rogue versions of _socket.pyd in directories occuring in sys.path. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: python 6 compilation failure on RHEL
On 8/20/2012 6:31 AM Ganesh Reddy K said... But, python compilation is not successfully done and showing a failure log. Below is the capture of the same. Please see failure log shown in the bottom of this mail. How to solve the failure modules mentioned in the log ( bsddb185, dl , imageop, sunaudiodev ) Please guide me to proceed further. You're done, unless you specifically need support for any of those specific modules. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: python 6 compilation failure on RHEL
On 8/20/2012 10:20 AM Walter Hurry said... On Mon, 20 Aug 2012 19:12:05 +0200, Kwpolska wrote: >Do you really need to compile python2.6? RHEL has packages for python, >and it's better s/better/sometimes easier > to use pre-compiled packages rather than compile them yourself. I concur, but FYI the version of Python with RHEL5 is 2.4. Still, OP should stick with that unless there is a pressing reason. Hence, the 2.6 install. Learn-to-trim-ly y'rs, Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: python 6 compilation failure on RHEL
On 8/20/2012 11:37 AM Walter Hurry said... On Mon, 20 Aug 2012 11:02:25 -0700, Emile van Sebille wrote: On 8/20/2012 10:20 AM Walter Hurry said... I concur, but FYI the version of Python with RHEL5 is 2.4. Still, OP should stick with that unless there is a pressing reason. Hence, the 2.6 install. First, sorry for my omission to trim. Second, the reason for recommending that OP stick to the Red Hat provided version (unless there is a pressing reason) is the question of the already-paid-for Red Hat support. Generally, when you compile from source the binaries will install to /usr/local/bin and not be in conflict with RH's install version. And for that matter, if OP is forced to a later Python 2 version than 2.4, why not 2.7.3? Package dependencies. If the OP intends to install a package that doesn't support other than 2.6, you install 2.6. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: python 6 compilation failure on RHEL
On 8/20/2012 1:55 PM Walter Hurry said... On Mon, 20 Aug 2012 12:19:23 -0700, Emile van Sebille wrote: Package dependencies. If the OP intends to install a package that doesn't support other than 2.6, you install 2.6. It would be a pretty poor third party package which specified Python 2.6 exactly, rather than (say) "Python 2.6 or later, but not Python 3" It doesn't need to be a poorly supported third party package to require a non-current version of python -- just something as simple as an up and running application. Suppose you're migrating an application to new hardware. To make it interesting, assume it's a 10 year old zope application. It's likely that to minimize effort you'll gather (assuming you didn't save your sources - you do install from source, right?) and install the versions prescribed. Of course, if you're comfortable upgrading to the latest release then then, by all means, do so. For me, python is used for for dozens of rather significant one-offs that I prefer not to upgrade. Why mess with a working app. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: python 6 compilation failure on RHEL
On 8/20/2012 9:34 PM John Nagle said... After a thread of clueless replies, s/clueless/unread Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Filter versus comprehension (was Re: something about split()???)
On 8/24/2012 3:03 PM Terry Reedy said... On 8/24/2012 5:56 PM, Dennis Lee Bieber wrote: On Fri, 24 Aug 2012 19:03:51 + (UTC), Walter Hurry declaimed the following in gmane.comp.python.general: Google Groups sucks. These are computer literate people here. Why don't they just use a proper newsreader? Probably because their ISP doesn't offer a free server Python lists are available on the free gmane mail-to-news server. I'm getting high load related denials with the gmane connections a lot recently so I'm open to alternatives. Suggestions or recommendations? Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Time Bound Input in python
On 9/3/2012 3:01 AM Vikas Kumar Choudhary said... Hi I though of taking time bound input from user in python using "input" command. it waits fro infinite time , but I want to limit the time after that user input should expire with none. Please help. Googling yields http://stackoverflow.com/questions/1335507/keyboard-input-with-timeout-in-python among others. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Error 32 - Broken Pipe . Please Help!!
On 9/4/2012 10:08 AM Sreenath k said...
Error:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File
"/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/monitor.py",
line 575, in run
already_pickled=True)
File "/usr/lib/python2.7/dist-packages/spyderlib/utils/bsdsocket.py", line
24, in write_packet
sock.send(struct.pack("l", len(sent_data)) + sent_data)
error: [Errno 32] Broken pipe
Code :
So, what code is invoking spyderlib stuff that's causing the error?
Emile
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to print something only if it exists?
On 9/6/2012 10:59 AM [email protected] said... I want to print a series of list elements some of which may not exist, e.g. I have a line:- print day, fld[1], balance, fld[2] fld[2] doesn't always exist (fld is the result of a split) so the print fails when it isn't set. I know I could simply use an if but ultimately there may be more elements of fld in the print and the print may well become more complex (most like will be formatted for example). Thus it would be good if there was some way to say "print this if it exists". You may be better off ensuring that fld is an appropriate length. One way may be tweaking the split to return the right numbers of elements: >>> T = "1,2,3" >>> flds = (T+","*5).split(",")[:5] >>> flds ['1', '2', '3', '', ''] Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: SAP MM Cupertino, CA
On 9/10/2012 7:58 AM Ramchandra Apte said... On Monday, 10 September 2012 18:51:10 UTC+5:30, Suresh Kumar wrote: delete the original message. Marking this as abusive in Google Groups - this seems like spam. Please explain what does this have to do with Python. Please learn to trim -- your reposting of the entire 'abusive' post is in and of itself abusive. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Guides for communicating with business accounting systems
On 9/13/2012 8:02 AM Ben Finney said... Howdy all, What material should a team of programmers read before designing a database model and export format for sending commerce transactions to a business accounting system? The only standard I'm aware of is the EDI specification which I first encountered in the mid 70's and which is updated routinely. The full spec is the size of a telephone book (do they even still make those?) and both trading partners select from it the documents they intend to exchange. The back end integration is then left to both parties. If your data structure is sufficient to supply the content expected in the EDI specs for the documents you'd expect to exchange you should be OK on your database model. Unfortunately, the spec resembles the RS232 spec in that it leaves the details as an implementation issue to be settled between the two trading partners. Another problem is that the spec is privately (through an association) controlled and I've often had issues getting my hands on the proper documentation when I wasn't working with a trading partner. (I didn't want to pay the association fees to join and thereby gain access to the documentation directly.) There's a good overview at http://www.linktionary.com/e/edi.html HTH, Emile I'm especially not wanting ad hoc advice in this thread; this is surely an old, complex problem with a lot of ground already covered. Primers on pitfalls to avoid and non-obvious best practices are what I'd like to be directed toward. Constraints: * The shop is already written, and is maintained internally. Ideally we would use a widely-tested and third-party-maintained solution, but that's a struggle still ahead of us. For now, we must work with our private code base. * None of the developer team are have much experience with the field of business accounting, so if possible we need to learn from the past design mistakes of others without making them ourselves. * Our application is operating in Australia, with the sales tax tracking requirements that come with that. Australia-specific information is particularly desirable. * The business has switched to a different accounting service recently; it may well change again soon. We want to at least consider robustness of our shop's transaction tracking design in the face of a possible future switch to a different accounting system. I'm happy to asnwer questions, but I'm not about to hash out the design in this thread; that's our development team's job. What I want is pointers to a putative “What every programmer needs to know about storing commercial transactions for business accounting” general guide. Does that information already exist where I can point our team to it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?)
On 9/19/2012 12:50 PM ashish said... Hi c.l.p folks Here is my situation 1. I have two machines. Lets call them 'local' & 'remote'. Both run ubuntu & both have python installed 2. I have a python script, local.py, running on 'local' which needs to pass arguments ( 3/4 string arguments, containing whitespaces like spaces, etc ) to a python script, remote.py running on 'remote' (the remote machine). I have the following questions: 1. What's the best way to accomplish my task ? Check out http://rpyc.sourceforge.net/ -- It's reasonably lightweight and has been working well for our similar situation. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: technologies synergistic with Python
On 9/21/2012 2:59 PM Ethan Furman said... ...if my dream job is one that consists mostly of Python, and might allow telecommuting? Hi Ethan, I have an open position in my two man office I've tried to fill a couple times without success that is predominately python and would allow for telecommuting. I'm looking for a third member of the team that will focus on back end development integrating various systems through to an open source python platform. Where are you located? I'm on the SF Peninsula. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: One of my joomla webpages has been hacked. Please help.
On 9/26/2012 6:06 PM Wayne Werner said... On Sun, 23 Sep 2012, Dwight Hutto wrote: We're the borg. Oh, so you *are* a robot. That does explain your posts ;) Damn. Now I'll forever more hear Stephen Hawkin's voice as I read the repeated contexts. Maybe that'll help. EMile -- http://mail.python.org/mailman/listinfo/python-list
Re: test
On 9/27/2012 2:58 PM Rikishi42 said... Inboxes? What is this, usenet or email ? Yes. Both. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: how to insert random error in a programming
Debashish Saha wrote: how to insert random error in a programming? Make the changes late in the day then leave for the weekend? Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: numpy - 2D matrix/array - initialization like in Matlab...
someone wrote:
How to initialize my array directly using variables ?
It could also be that I wanted:
test11 = 1
test12 = 1.5
test13 = 2
test21 = 0
test22 = 5
Dx = numpy.matrix('test11 test12 test13; test21 test22 -0.5; 0 -0.5 1.5')
Etc... for many variables...
Appreciate ANY help, thank you very much!
You could use string interpolation:
Dx = numpy.matrix('%s %s %s; %s %s -0.5; 0 -0.5 1.5'
% (test11 test12 test13 test21 test22))
Emile
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python does not take up available physical memory
On 10/19/2012 10:08 AM, Pradipto Banerjee wrote: Hi, I am trying to read a file into memory. The size of the file is around 1 GB. I have a 3GB memory PC and the Windows Task Manager shows 2.3 GB available physical memory when I was trying to read the file. I tried to read the file as follows: fdata = open(filename, ‘r’).read() I got a “MemoryError”. I was watching the Windows Task Manager while I run the python command, and it appears that python **perhaps** never even attempted to use more memory but gave me this error. Is there any reason why python can’t read a 1GB file in memory even when a 2.3 GB physical memory is available? The real issue is likely that there is more than one copy of the file in memory somewhere. I had a similar issue years back that I resolved by using numeric (now numpy?) as it had a more efficient method of importing content from disk. Also realize that windows may not allow the full memory to user space. I'm not sure what exactly the restrictions are, but a 4Gb windows box doesn't always get you 4Gb of memory. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: get each pair from a string.
On 10/21/2012 11:33 AM, Vincent Davis wrote: I am looking for a good way to get every pair from a string. For example, input: x = 'apple' output 'ap' 'pp' 'pl' 'le' I am not seeing a obvious way to do this without multiple for loops, but maybe there is not :-) In the end I am going to what to get triples, quads... also. How far have you gotten? Show us the loops you're trying now and any errors you're getting. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: get each pair from a string.
On 10/21/2012 11:51 AM, Ian Kelly wrote: On Sun, Oct 21, 2012 at 12:33 PM, Vincent Davis wrote: I am looking for a good way to get every pair from a string. For example, input: x = 'apple' output 'ap' 'pp' 'pl' 'le' I am not seeing a obvious way to do this without multiple for loops, but maybe there is not :-) Use the "pairwaise" recipe from the itertools docs: def pairwise(iterable): "s -> (s0,s1), (s1,s2), (s2, s3), ..." a, b = tee(iterable) next(b, None) return izip(a, b) In the end I am going to what to get triples, quads... also. Generalizing: def nwise(iterable, n=2): iters = tee(iterable, n) for i, it in enumerate(iters): for _ in range(i): next(it, None) return izip(*iters) Hmmm. And it seemed so straightforward to me as: >>> groupsize=3 >>> a = "applesauce" >>> for i in range(len(a)-groupsize+1): a[i:i+groupsize] ... 'app' 'ppl' 'ple' 'les' 'esa' 'sau' 'auc' 'uce' Other than adding depth to my knowledge of the ever growing standard library, is there a reason to prefer pairwise over my simple loop? Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: get each pair from a string.
On 10/21/2012 12:06 PM, Ian Kelly wrote: On Sun, Oct 21, 2012 at 12:58 PM, Vincent Davis wrote: x = 'apple' for f in range(len(x)-1): print(x[f:f+2]) @Ian, Thanks for that I was just looking in to that. I wonder which is faster I have a large set of strings to process. I'll try some timings if I get a chance later today. The solution you came up with is probably faster, but less general -- it will only work on sliceable sequences like strings, not arbitrary iterables. So the simple loop is the right answer for sliceable sequences like strings, but not if your code needs to deal with arbitrary iterables such as those that the standard library authors are expected to handle. So, as OP's a self confessed newbie asking about slicing, why provide an example requiring knowledge of tee, enumerate, next and izip? def nwise(iterable, n=2): iters = tee(iterable, n) for i, it in enumerate(iters): for _ in range(i): next(it, None) return izip(*iters) It's good that the standard library provides these tools as a convenience, but when all you need is a derringer, why reach for a howitzer? Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: get each pair from a string.
On 10/21/2012 9:19 PM, Ian Foote wrote: On 22/10/12 09:03, Emile van Sebille wrote: So, as OP's a self confessed newbie asking about slicing, why provide an example requiring knowledge of tee, enumerate, next and izip? Because not only the newbie will read the thread? I for one was interested to see all the different possible approaches, and their upsides and downsides. Fair -- I get concerned that newcomers are faced with a much higher cost of entry when answers to their apparently simple problems require knowledge of specific functions in specific library modules to solve. This presents a very high bar as my quick local test (help(); modules) shows 398 modules! In this case the only requirement should have been a quick pass through the tutorial which should be enough to solve most problems. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 10/23/2012 4:35 PM, emile wrote: So, let's see, at that point in time (building backward) you've got probably somewhere close to 400-500Gb in memory. My guess -- probably not so fast. Thrashing is sure to be a factor on all but machines I'll never have a chance to work on. I went looking for a machine capable of this and got about halfway there with http://www.tech-news.com/publib/pl2818.html which allows up to 248Gb memory -- near as I can tell the price for the maxed out system is $2,546,200. Plus $3k/mo maintenance. Memory's still not quite enough, but I'll bet it's fast. And a lot more reasonable at $1000 per Gb of memory particularly when contrasted to the $1000 I paid for a single Mb of memory back in 1984 or thereabouts. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a simpler way to modify all arguments in a function before using the arguments?
[email protected] wrote: Using a decorator works when named arguments are not used. When named arguments are used, unexpected keyword error is reported. Is there a simple fix? Extend def wrapper(*args) to handle *kwargs as well Emile Code: - from functools import wraps def fix_args(fn): @wraps(fn) def wrapper(*args): args = (arg.replace('_', '') for arg in args) return fn(*args) return wrapper @fix_args def foo(a1="", a2="", b1="", b2=""): print(a1) print(a2) print(b1) print(b2) foo ('a1a1_x', 'a2a2_x', 'b1b1_x', 'b2b2_x') foo (a1='a1a1_x', a2='a2a2_x', b1='b1b1_x', b2='b2b2_x') Results: a1a1x a2a2x b1b1x b2b2x Traceback (most recent call last): File "C:\WORK\masterDB_Update\argtest.py", line 19, in foo (a1='a1a1_x', a2='a2a2_x', b1='b1b1_x', b2='b2b2_x') TypeError: wrapper() got an unexpected keyword argument 'a1' -- http://mail.python.org/mailman/listinfo/python-list
