ANN: SfePy 2013.1

2013-02-28 Thread Robert Cimrman

I am pleased to announce release 2013.1 of SfePy.

Description
---
SfePy (simple finite elements in Python) is a software for solving
systems of coupled partial differential equations by the finite element
method. The code is based on NumPy and SciPy packages. It is distributed
under the new BSD license.

Home page: http://sfepy.org
Downloads, mailing list, wiki: http://code.google.com/p/sfepy/
Git (source) repository, issue tracker: http://github.com/sfepy

Highlights of this release
--
- unified use of stationary and evolutionary solvers
- new implicit adaptive time stepping solver
- elements of set and nodes of set region selectors
- simplified setting of variables data

For full release notes see http://docs.sfepy.org/doc/release_notes.html#id1
(rather long and technical).

Best regards,
Robert Cimrman and Contributors (*)

(*) Contributors to this release (alphabetical order):

Vladimír Lukeš, Matyáš Novák
--
http://mail.python.org/mailman/listinfo/python-announce-list

   Support the Python Software Foundation:
   http://www.python.org/psf/donations/


Wing IDE 4.1.11 released

2013-02-28 Thread Wingware

Hi,

Wingware has released version 4.1.11 of Wing IDE, our integrated development
environment designed specifically for the Python programming language.

Wing IDE provides a professional quality code editor with vi, emacs, and 
other
key bindings, auto-completion, call tips, refactoring, context-aware 
auto-editing,
a powerful graphical debugger, version control, unit testing, search, 
and many

other features.  For details see http://wingware.com/

This minor release includes:

  * Right click on tool tabs to assign a key binding to the tool
  * Allow auto-stripping trailing white space to be limited to project 
files

  * Support for Subversion version 1.7.x
  * Allow introduce variable refactoring in more contexts
  * Support opening files with Wing via the Linux .desktop file
  * Improve auto-editing fixups
  * Fix keep external console open under Python 3
  * Restore original editor and focus after refactoring operations complete
  * Show skipped icon for groups of unit tests that were all skipped
  * 13 other bug fixes and minor improvements

For a complete change log see 
http://wingware.com/pub/wingide/4.1.11/CHANGELOG.txt


Free trial: http://wingware.com/wingide/trial
Downloads: http://wingware.com/downloads
Feature matrix: http://wingware.com/wingide/features
More information: http://wingware.com/
Sales: http://wingware.com/store/purchase
Upgrades: https://wingware.com/store/upgrade

Questions?  Don't hesitate to email us at sa...@wingware.com.

Thanks,

--

Stephan Deibel
Wingware | Python IDE
Advancing Software Development

www.wingware.com
--
http://mail.python.org/mailman/listinfo/python-announce-list

   Support the Python Software Foundation:
   http://www.python.org/psf/donations/


Re: Python Speed

2013-02-28 Thread Stefan Behnel
Steven D'Aprano, 28.02.2013 08:05:
 On Wed, 27 Feb 2013 21:11:25 -0500, Terry Reedy wrote:
 
 There is a problem with timer overhead for sub-microsecond operations.
 In interactive use, the code is compiled within a function that gets
 called. The string 'abc需' should be stored as a constant in the code
 object. To force repeated string operation, one should either time from
 command line or do an operation, as with the example above. I notice
 that the first of 3 times is almost always higher for some reason.
 
 I am not an expert on this, but I suspect the problem may have something 
 to do with CPU pipelines and cache. The first time the timer runs, the 
 cache is empty, and you get a slightly higher time. Subsequently there 
 are not as many CPU cache misses, and the code runs more quickly.

Well, the default loop iteration count is 100, so warming up any caches
might make a little difference at the very beginning but should rarely have
a major impact on the overall running time, as each iteration only changes
the final result by 1/100 of its runtime.

However, it's best to run timeit as a main program (python -m timeit),
because the way it works then is that it first runs the code a couple of
times to see how often it should repeat it in a loop to get meaningful
results. Only *then* it starts benchmarking it. That initial testing phase
should usually be enough to warm up any caches, so that you'd get better
results. You can still get the results of all repeated runs if you pass -v.

Stefan


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Speed

2013-02-28 Thread Steven D'Aprano
On Wed, 27 Feb 2013 23:40:22 -0800, jmfauth wrote:

 As long as you are attempting to work with a composite scheme not
 working with a unique set of characters, not only it will not work
 (properly/with efficiency), it can not work.

What's a composite scheme?


 This not even a unicode problem. This is true for every coding scheme.
 That's why we have, today, all these coding schemes, coding scheme: ==
 set of characters; != set of encoded characters.

This doesn't make any sense to me. What do you think this means?

Oh, and the actual reason we have all these coding schemes is for 
historical reasons. Just about every PC manufacturer invented their own 
encoding for whatever characters they cared about.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python newbie trying to embed in C++

2013-02-28 Thread Marwan Badawi

On 27/02/2013 10:26, Ian Kelly wrote:

On Wed, Feb 27, 2013 at 1:51 AM, Marwan lar...@free.fr wrote:

When I run the generated exe, I get errors about the functions not
existing...

TestPython.exe test Hello
AttributeError: 'module' object has no attribute 'Hello'
Cannot find function Hello


test is the name of a module in the standard library.  My guess
would be that for some reason it's importing that module rather than
your test.py.  Make sure that test.py can be found on your sys.path,
and perhaps change the name of your module to reduce confusion.

I just noticed that my reply went to the message sender and not to the 
newsgroup, so I'm posting again: thanks, that was it. Just renaming my 
test.py file solved the problem.


%M
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python newbie trying to embed in C++

2013-02-28 Thread Marwan Badawi

On 27/02/2013 16:17, Christian Gollwitzer wrote:

Am 27.02.13 09:51, schrieb Marwan:

And I'd appreciate it if you could give me pointers to how to easily
call Python from C++.


Maybe you can use boost::python?

http://www.boost.org/doc/libs/1_53_0/libs/python/doc/

Cave: I haven't used it and don't know if it is up-to-date.

 Christian

I just noticed that my reply went to the message sender and not to the 
newsgroup, so I'm posting again: thanks, I'll look into that.


%M
--
http://mail.python.org/mailman/listinfo/python-list


Re: Project Based python tutorials

2013-02-28 Thread Jean-Michel Pichavant


- Original Message -
 On Wednesday, February 27, 2013 2:31:11 AM UTC-6, Alvin Ghouas wrote:
 
  So, I desided to start learning programming a few months
  ago and by now i feel pretty confident about the basics of
  the python language, and programming in general.
  Variables, loops, conditionals, data structures, methods
  and even some object oriented programming, are all
  familiar consepts.
 
 Congratulations on your accomplishment. However, what you describe
 would only be a good grasp of *very* basic and very *generic*
 aspects of programming in general. There is much MUCH more to learn
 before you start authoring a resume to Google or jump head first
 into a large scale open source project.
 
  As i want to become a better programmer, i figured the
  next step would be to start working on some bigger and
  more complex projects.Yet despite my numerouse web searchs
  for project based tutorials,i cant seem to find any good
  ones.
 
 Hold on just a minute!
 
 Before you decide to start participating in outside projects may we
 have a list of some of the software you've written for yourself?
 (With all due respect) I very seriously doubt that someone with only
 a few months of programming experience is ready for the real
 world.
 
  I have no trouble with understanding the concepts of
  programming, however I find it quite difficult to take it
  to the next level. So, is there anyone out there willing
  to share some experience? I would be really grateful.
 
 Well how can we possibly know what the next level means to you when
 you failed to offer examples of your experience besides: loops,
 variables, data structures, etc... Please provide a list of the
 types of programs you have written. Have you written any system
 tool? What about GUI applications? What about every programmers wet
 dream: THE WORLDS BEST TEXT EDITOR! What about libraries? Details,
 details!

Rick, aren't you recruiting for you py4000 project ?

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python newbie trying to embed in C++

2013-02-28 Thread Gisle Vanem

Marwan Badawi marwan.bad...@inria.fr wrote:

I just noticed that my reply went to the message sender and not to the 
newsgroup, so I'm posting again: thanks, I'll look into that.


Yes, I often do that too; i.e. I'm subscribed to python-list@python.org
and get all messages from comp.lang.python mirrored to the ML a bit later.
I prefer the mailing-list over comp.lang.python since my NNTP server
(eternal-september.org) is rather slow and my ISP has deprecated NNTP 
long time ago. 


I saw you uses Thunderbird on Windows. I'm not sure how it by default handles
a reply-to when there is no Reply-to field in the header. To the address in 
From / Sender or what? 


I wish the NNTP-mailing list gateway could add a Reply-to: 
python-list@python.org.
Since I'm getting the messages via the ML, I think it would be logical that the replies 
should by default go to the ML too.


--gv



--
http://mail.python.org/mailman/listinfo/python-list


Re: mp3

2013-02-28 Thread fabriceS

Le 28/02/2013 01:07, alex23 a écrit :

On Feb 28, 7:58 am, fabriceS fabrice.sinc...@wanadoo.fr wrote:

Is anybody know how to get the lenght (in seconds) of a mp3 file ?


Try eyeD3: https://pypi.python.org/pypi/eyeD3

  import eyed3
  mp3 = eyed3.load(r'pygame\examples\data\house_lo.mp3')
  mp3.info.time_secs
 7




  it work fine

greats
--
http://mail.python.org/mailman/listinfo/python-list


Re: Nuitka now supports Python 3.2

2013-02-28 Thread Steven D'Aprano
On Thu, 28 Feb 2013 08:07:55 +0100, Stefan Behnel wrote:

 Steven D'Aprano, 26.02.2013 13:18:
 Nuitka is an implementation of Python written in C++. At the moment it
 is claimed to be about 2.5 times as fast as CPython running the pystone
 benchmark.
 
 Could we please get to the habit of not citing results of benchmarks
 that *any* static analysis phase will just optimise away either
 completely or in major parts?

Are you saying that the pystone benchmark contains such an empty loop?

Do you know for a fact that Nuitka performs such an optimization based on 
static analysis?

Are you saying that this one test is so significant that it invalidates 
the entire pystone benchmark?



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


raw format string in string format method?

2013-02-28 Thread Helmut Jarausch
Hi,

I'd like to print a string with the string format method which uses
{0}, ...

Unfortunately, the string contains TeX commands which use lots of
braces. Therefore I would have to double all these braces just for the
format method which makes the string hardly readable.

Is there anything like a raw format string and any other means
to circumvent this?

Many thanks for a hint,
Helmut.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raw format string in string format method?

2013-02-28 Thread Chris Angelico
On Fri, Mar 1, 2013 at 1:11 AM, Helmut Jarausch jarau...@skynet.be wrote:
 Hi,

 I'd like to print a string with the string format method which uses
 {0}, ...

 Unfortunately, the string contains TeX commands which use lots of
 braces. Therefore I would have to double all these braces just for the
 format method which makes the string hardly readable.

 Is there anything like a raw format string and any other means
 to circumvent this?

You could use a different string formatting function, such as
percent-formatting:

Hello, {0}, this is %s % some_string

The {0} will be output literally, and the %s will be replaced by the
string. Braces are ignored, percent signs are significant.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raw format string in string format method?

2013-02-28 Thread Helmut Jarausch
On Fri, 01 Mar 2013 01:22:48 +1100, Chris Angelico wrote:

 On Fri, Mar 1, 2013 at 1:11 AM, Helmut Jarausch jarau...@skynet.be
 wrote:
 Hi,

 I'd like to print a string with the string format method which uses
 {0}, ...

 Unfortunately, the string contains TeX commands which use lots of
 braces. Therefore I would have to double all these braces just for the
 format method which makes the string hardly readable.

 Is there anything like a raw format string and any other means to
 circumvent this?
 
 You could use a different string formatting function, such as
 percent-formatting:
 
 Hello, {0}, this is %s % some_string
 
 The {0} will be output literally, and the %s will be replaced by the
 string. Braces are ignored, percent signs are significant.
 
 ChrisA

Originally I had used percent-formatting
But isn't  it deprecated in Python 3.X ?

Thanks,
Helmut.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raw format string in string format method?

2013-02-28 Thread Chris Angelico
On Fri, Mar 1, 2013 at 1:42 AM, Helmut Jarausch jarau...@skynet.be wrote:
 On Fri, 01 Mar 2013 01:22:48 +1100, Chris Angelico wrote:

 On Fri, Mar 1, 2013 at 1:11 AM, Helmut Jarausch jarau...@skynet.be
 wrote:
 Hi,

 I'd like to print a string with the string format method which uses
 {0}, ...

 Unfortunately, the string contains TeX commands which use lots of
 braces. Therefore I would have to double all these braces just for the
 format method which makes the string hardly readable.

 Is there anything like a raw format string and any other means to
 circumvent this?

 You could use a different string formatting function, such as
 percent-formatting:

 Hello, {0}, this is %s % some_string

 The {0} will be output literally, and the %s will be replaced by the
 string. Braces are ignored, percent signs are significant.

 ChrisA

 Originally I had used percent-formatting
 But isn't  it deprecated in Python 3.X ?

No, it's still fully supported. Every now and then someone suggests
that it's worse than .format() for some reason or another, but the
fact is that it's not going away. Use whichever one makes the most
sense.

Yes, this is a slight violation of one obvious way to do it. But
it's handy to have both format methods; they have overlapping but
distinct feature sets.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raw format string in string format method?

2013-02-28 Thread Peter Otten
Helmut Jarausch wrote:

 I'd like to print a string with the string format method which uses
 {0}, ...
 
 Unfortunately, the string contains TeX commands which use lots of
 braces. Therefore I would have to double all these braces just for the
 format method which makes the string hardly readable.
 
 Is there anything like a raw format string and any other means
 to circumvent this?
 
 Many thanks for a hint,
 Helmut.

While percent-formatting is probably the way to go here is a hack to replace 
the braces with custom characters:

import string

class SwapFormatter(string.Formatter):
custom = 
braces = {}
swap = {ord(p): q for p, q in zip(custom + braces, braces + custom)}

def format(self, format_string, *args, **kw):
format_string = format_string.translate(self.swap)
return super().format(format_string, *args, **kw)

def parse(self, format_string):
return ((t[0].translate(self.swap),) + t[1:]
for t in super().parse(format_string))

myformat = SwapFormatter().format
print(myformat( {} {{0}} 2 {foo} 1:width ,
   alpha, 42, gamma, foo=delta, width=5))


-- 
http://mail.python.org/mailman/listinfo/python-list


سعر بلاك بيرى blackberry z10- z10

2013-02-28 Thread 23alagmy
سعر بلاك بيرى   blackberry z10-  z10

http://natigtas7ab.blogspot.com/2013/02/z10-blackberry-z10_23.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Issue with continous incrementing of unbroken sequence for a entire working day

2013-02-28 Thread Morten Engvoldsen
Hi team,
I need to run a batch of sales records and  the batch has serial_number
filed to store the serial number of the sales record. The serial number
should be set to  1 everyday when the batch runs first time in a day and
the maximum serial number could be 1000.

So when the batch runs first time in a day and if it has 10 records, so the
last serial number will be 10. And when the batch runs 2nd time in same
day, the serial number should start from 11.  In this way serial_number
will increment as an unbroken series throughout the entire working day. The
next day when the batch runs first time the serial number will reset to 1.

Now this could be sample code how the program can count the sequence for a
batch:

def salesrecord():
serial_number = 1
for i in selesrecord:
print first_sales_record
serial_number += 1
print serial_number

salesrecord()

So if the batch has 10 records and last serial number of first batch is 10,
then when the batch runs second time in the same day, how the
'serial_number' will get the value of 10 and then continue the serial
number for the same day,  then for next day again the serial number will
start from 1.

Can you let me know how can i achive this in python? As i am in learning
phase of python, can you let me know what would be good approach to do this
in python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Speeding up Python's exit

2013-02-28 Thread Steven D'Aprano
I just quit an interactive session using Python 2.7 on Linux. It took in 
excess of twelve minutes to exit, with the load average going well past 9 
for much of that time.

I think the reason it took so long was that Python was garbage-collecting 
a giant dict with 10 million entries, each one containing a list of the 
form [1, [2, 3], 4]. But still, that's terribly slow -- ironically, it 
took longer to dispose of the dict (12+ minutes) than it took to create 
it in the first place (approx 3 minutes, with a maximum load of 4). 

Can anyone explain why this was so painfully slow, and what (if anything) 
I can do to avoid it in the future?

I know there is a function os._exit which effectively kills the Python 
interpreter dead immediately, without doing any cleanup. What are the 
consequences of doing this? I assume that the memory used by the Python 
process will be reclaimed by the operating system, but other resources 
such as opened files may not be.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speeding up Python's exit

2013-02-28 Thread Neil Cerutti
On 2013-02-28, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 Can anyone explain why this was so painfully slow, and what (if
 anything) I can do to avoid it in the future?

I think your explanation makes sense. Maybe the nested nature of
the strings was causing it to churn looking for circular
references?

Disabling gc before exiting might do the trick, assuming you're
assiduously managing other resources with context managers.

gc.disable()
exit()


-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Largest possible size for executemany() in PEP-249 (Database API)

2013-02-28 Thread Roy Smith
I'm trying to batch up inserts to a database using MySQLdb.  When I
get to something over 10,000 records per call, I get an exception:

_mysql_exceptions.OperationalError: (1153, Got a packet bigger than
'max_allowed_packet' bytes)

Is there any way (other than trial and error) to know how many records
I can pass in one call before I blow up?  As a practical matter, if I
do batches of 1000 per call, I've probably gotten as much performance
enhancement as I need, but it would be nice to know if there's a
useful way to determine exactly what the maximum is.
-- 
http://mail.python.org/mailman/listinfo/python-list


Import web content to csv only if values are different from those of an excel sheet

2013-02-28 Thread io
Hi, 

i have the following python script that reads json data from a website 
and writes it in a csv file that i will then import to excel. (i have 
just started since a week with py so i'm a noob!) :
---

import json
import urllib
import csv

url = http://bitcoincharts.com/t/markets.json;
response = urllib.urlopen(url);
data = json.loads(response.read())

f = open(/home/io/markets.csv,wb)
c = csv.writer(f)

# write headers
c.writerow([Currency,Symbol,Bid, Ask, Volume])

for d in data :
if d[currency]  SLL:  #esclude la valuta di secondlife SLL
if d[bid] is not None and d[ask] is not None:
c.writerow([str(d[currency]),str(d[symbol]),str(d
[bid]),str(d[ask]),str(d[currency_volume])])

--

I have an .ods file (libre calc - i'm on linux) where i have in a sheet 
called exclusions a list of names (symbol) the i want to exclude during 
the import from web.

I would like to modify my script so that it can parse each row in the 
exclusion sheet and if symbol  = parsed row value then don't write 
it to the csv file ... to loop on all values in the exclusion sheet.

I know it's certainly possible but i don't know how to do that.  (if it 
results easier having the exclusion list in a text file it's not a 
problem, i'm not really stuck with librecalc!)

Thanks in advance to any helpful soul!  :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] PyLint 0.27 / logilab-astng 0.24.2

2013-02-28 Thread Sylvain Thénault
Hi there,

I'm very pleased to announce the release of pylint 0.27 [1] and
logilab-astng 0.24.2 [2] . There has been a lot of enhancements and
bug fixes since the latest release, so you're strongly encouraged
to upgrade. See ChangeLog for details.

Many thanks to all the people who contributed to this release!

[1] http://www.logilab.org/project/pylint/0.27.0 /
[2] http://www.logilab.org/project/logilab-astng/0.24.2

Enjoy!
-- 
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:   http://www.logilab.fr/services
CubicWeb, the semantic web framework:http://www.cubicweb.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speeding up Python's exit

2013-02-28 Thread Chris Angelico
On Fri, Mar 1, 2013 at 4:31 AM, Devin Jeanpierre jeanpierr...@gmail.com wrote:
 On Thu, Feb 28, 2013 at 12:06 PM, Chris Angelico ros...@gmail.com wrote:
 Is it any different if you create a deliberate reference loop and then
 stuff it into some module somewhere? That would force it to be kept
 until interpreter shutdown, and then a cyclic garbage collection after
 that, which quite probably would be never run. A stupid trick,
 perhaps, but it might work; I tested it with a dummy class with a
 __del__ method and it wasn't called. Putting it into some other module
 may not be necessary, but I don't know what happens with the
 interactive interpreter and what gets freed up when.

 __del__ is never called for cyclic references.

D'oh. Test is flawed, then. But is the theory plausible? That the
cycle detector won't be called on exit after other modules get freed?

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speeding up Python's exit

2013-02-28 Thread Devin Jeanpierre
On Thu, Feb 28, 2013 at 12:31 PM, Devin Jeanpierre
jeanpierr...@gmail.com wrote:
 On Thu, Feb 28, 2013 at 12:06 PM, Chris Angelico ros...@gmail.com wrote:
 Is it any different if you create a deliberate reference loop and then
 stuff it into some module somewhere? That would force it to be kept
 until interpreter shutdown, and then a cyclic garbage collection after
 that, which quite probably would be never run. A stupid trick,
 perhaps, but it might work; I tested it with a dummy class with a
 __del__ method and it wasn't called. Putting it into some other module
 may not be necessary, but I don't know what happens with the
 interactive interpreter and what gets freed up when.

 __del__ is never called for cyclic references.

Sorry, I posted too early. Not only is __del__ never called, but
__del__ is the reason the cycles aren't collected. I don't know if
your trick will work without __del__.

-- Devin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speeding up Python's exit

2013-02-28 Thread Devin Jeanpierre
On Thu, Feb 28, 2013 at 12:06 PM, Chris Angelico ros...@gmail.com wrote:
 Is it any different if you create a deliberate reference loop and then
 stuff it into some module somewhere? That would force it to be kept
 until interpreter shutdown, and then a cyclic garbage collection after
 that, which quite probably would be never run. A stupid trick,
 perhaps, but it might work; I tested it with a dummy class with a
 __del__ method and it wasn't called. Putting it into some other module
 may not be necessary, but I don't know what happens with the
 interactive interpreter and what gets freed up when.

__del__ is never called for cyclic references.

-- Devin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with continous incrementing of unbroken sequence for a entire working day

2013-02-28 Thread Vytas D.
Hi,

If you want to have one program running forever and printing sales_records,
you would do (one of the possibilities) something like this:
def salesrecord(serial_number):

for i in salesrecord:
print first_sales_record
serial_number += 1
print serial_number
return serial_number

if __name__ == '__main__':
serial_number = 1

# Runs this loop until killed
while True
do some stuff: clean serial_number, if day changed, calculate
salesrecord etc.

serial_number = salesrecord(serial_number)

If you want to run your script so it finishes and then saves last value of
serial_number, so you can pass it to your script when it runs next time,
you should save the value to some file and read that file on every start of
your program.

Vytas


On Thu, Feb 28, 2013 at 4:31 PM, Morten Engvoldsen mortene...@gmail.comwrote:

 Hi team,
 I need to run a batch of sales records and  the batch has serial_number
 filed to store the serial number of the sales record. The serial number
 should be set to  1 everyday when the batch runs first time in a day and
 the maximum serial number could be 1000.

 So when the batch runs first time in a day and if it has 10 records, so
 the last serial number will be 10. And when the batch runs 2nd time in same
 day, the serial number should start from 11.  In this way serial_number
 will increment as an unbroken series throughout the entire working day. The
 next day when the batch runs first time the serial number will reset to 1.

 Now this could be sample code how the program can count the sequence for a
 batch:

 def salesrecord():
 serial_number = 1
 for i in selesrecord:
 print first_sales_record
 serial_number += 1
 print serial_number

 salesrecord()

 So if the batch has 10 records and last serial number of first batch is
 10, then when the batch runs second time in the same day, how the
 'serial_number' will get the value of 10 and then continue the serial
 number for the same day,  then for next day again the serial number will
 start from 1.

 Can you let me know how can i achive this in python? As i am in learning
 phase of python, can you let me know what would be good approach to do this
 in python.

 --
 http://mail.python.org/mailman/listinfo/python-list


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Breaking into descriptors

2013-02-28 Thread Dave Angel

On 02/28/2013 12:24 PM, Demian Brecht wrote:

class MyDescriptor(object):
 def __init__(self):
 self.foo = 'bar'

 def __get__(self, obj, type_):
 import pdb; pdb.set_trace()
 return self.do_something()

 def __set__(self, obj, val):
 self.foo = val

class C(object):
 foo = MyDescriptor()

C().foo

pdb doesn't break into the descriptor's __get__ method on C().foo. Is
this a known limitation of pdb, or possibly a(n) (un)known bug?




It halts (breaks) for me, in Python 2.7.3 on Linux

  /home/davea/temppython/demian.py(8)__get__()
 - return self.do_something()
 (Pdb) up
  /home/davea/temppython/demian.py(19)module()
 - obj = C().foo
 (Pdb)


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python newbie trying to embed in C++

2013-02-28 Thread Michael Torrie
On 02/28/2013 03:47 AM, Gisle Vanem wrote:
 I saw you uses Thunderbird on Windows. I'm not sure how it by default handles
 a reply-to when there is no Reply-to field in the header. To the address in 
 From / Sender or what? 

Thunderbird has a handy, reply to list button that works every time no
matter what the rely-to field is set to.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-28 Thread Rick Johnson
On Wednesday, February 27, 2013 11:57:05 PM UTC-6, alex23 wrote:
 On Feb 28, 2:53 pm, Rick Johnson rantingrickjohn...@gmail.com wrote:
  On Wednesday, February 27, 2013 10:18:46 PM UTC-6, alex23 wrote:
 [...]
 * Do you care about the evolution of Python or just give
 it lip service?
 
 I don't see any problems with how Python is developing now. Then
 again, I am pretty busy using it to write code.

So go write your code and stop trying to stymie the attempts of others who wish 
to improve Python. Your participation is NOT compulsory!

 * Do you have an ideas for the name of a Python grievance
 list?

 http://bugs.python.org/

Well thanks for actually answering a question directly, but we must dig deeper. 
Deciding the _name_ of a list is just one small detail, the most important 
question is this:

Q: Do you feel that the bug tracker should be a place where users discuss 
grievances that distract volunteers from fixing actual bugs?

I'm of the opinion that such discussions are more suited for an entry-level 
grievance list (such as: PyWarts).

 * What are your opinions of the state of both Tkinter and
 IDLE? Are you proud of these modules/packages?

 I don't use them, 

So again, why bother to stymie the attempts of others who DO use them? Crawl 
back under your rock and write some code.

 ...nor do I need to feel pride about any part of the
 Python standard library. Either something is useful to me or not.

That's a fairly selfish outlook Alex. 

Okay, maybe you don't care about the state of Python's stdlib, fine, but other 
people do. How does flinging poo on these people help anyone? But more 
importantly how does flinging poo reflect on your image in this community?

  * Why do you support Guido's continued reign of silence?

 Why do you inject hyperbole into everything you write?

The question is quite valid and your are diverting again!

  * But most importantly, do you not want the community/
  language to evolve or remain static?

 I already answered that above. [...] Can you provide a link to
 your improved tkinter package on PyPI? 

No, because my awesome re-write of Tkinter does not live at PyPI.

 Where is your draft PEP for its inclusion in the standard
 library?

I have not written a PEP on the subject. Are you suggesting that if i don't 
write a PEP my proposal is dead in the water? If so, this is exactly the kind 
of barriers that keep Python's stdlib in such a atrocious state!

What if i'm a horrible writer and a genius code artist? If the community judges 
the value of source code based on the rhetoric of a document describing the 
source code, then they are basing their judgments on folly. What happens if i 
am a seasoned programmer but English is my second language? 

It is my opinion that PEP are great, but they should not be compulsory to 
having your ideas seriously considered by the community. A great idea is a 
great idea, no matter how much fluff you add to it. Likewise, a poor idea is a 
poor idea, and no amount of fluff could ever make it better. In this sense, PEP 
are a waste of valuable time.

And let's not forget the irony here; the default reply for documentation issues 
is for the user to read the effing source!. Hmm, so *you* and others feel 
that reading source is compulsory for those *without* the ability to comprehend 
the source, and a waste of time for those *with* the ability to read source? Is 
this not the definition of hipocracy Alex? I have a feeling there is a bit of 
malevolence in there also.

Alex, your in ability to understand the asinine barriers a contributor to this 
community must negotiate is leading me to believe you have _insidious_ 
intentions.

 How is RickPython proceeding?

My personal Python fork is of no concern to this community, or this mailing 
list; STAY ON TOPIC!

  What is your opinion on anything Python related Alex?
 My biggest regret re Python is that you found it more
 appealing than Ruby and we got saddled with you instead.

Ahh, and this little off-hand statement uncovers the hidden truth. Regardless 
of your personal feeling of me, your underlying hatred of Python is *glaringly* 
apparent!

 You responded to a request for advice on learning how to
 handle complex projects with:
 
 Before you decide to start participating in outside projects may we
 have a list of some of the software you've written for yourself? (With
 all due respect) I very seriously doubt that someone with only a few
 months of programming experience is ready for the real world.

The OP of that thread asked for advice on large projects that we might 
recommend. I tend to prefer giving people good advice and only guessing when i 
have not other choice. In order to offer good advice i need to know first how 
experienced the OP is with programming (not only python, but all languages). 

The only hint the OP offered was this:


#  Quote   #

Re: Breaking into descriptors

2013-02-28 Thread Demian Brecht
On Thu, Feb 28, 2013 at 10:01 AM, Dave Angel da...@davea.name wrote:
 It halts (breaks) for me, in Python 2.7.3 on Linux


Okay, now I'm just confused. I ran this in terminal on OSX with both
2.7.3 and 3.4(dev) and both were exhibiting the same behaviour. I've
since closed the terminal and upon trying it in a newly created term,
cannot repro it.

Gremlins.

-- 
Demian Brecht
http://demianbrecht.github.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with continous incrementing of unbroken sequence for a entire working day

2013-02-28 Thread Morten Engvoldsen
Hi,
thanks for youe suggestion. I think i will go for your second option:

# Runs this loop until killed
while True
do some stuff: clean serial_number, if day changed, calculate salesrecord
etc.

serial_number = salesrecord(serial_number)


But, if i save the serial_ number value in file, then how  will it decide
to reset the serial number to '1' when the batch  runs on next working day.
What condition can be good, so that next day when the batch runs, it will
know it has to reset the value 1.  Also my batch will not automatcilly run
whole day, this is user's decision how many times he wants to run the batch
in a day. Can you elebrate more how can i do that ...

On Thu, Feb 28, 2013 at 6:43 PM, Vytas D. vytasd2...@gmail.com wrote:

 Hi,

 If you want to have one program running forever and printing
 sales_records, you would do (one of the possibilities) something like this:
 def salesrecord(serial_number):

 for i in salesrecord:

 print first_sales_record
 serial_number += 1
 print serial_number
 return serial_number

 if __name__ == '__main__':
 serial_number = 1

 # Runs this loop until killed
 while True
 do some stuff: clean serial_number, if day changed, calculate
 salesrecord etc.

 serial_number = salesrecord(serial_number)

 If you want to run your script so it finishes and then saves last value of
 serial_number, so you can pass it to your script when it runs next time,
 you should save the value to some file and read that file on every start of
 your program.

 Vytas


 On Thu, Feb 28, 2013 at 4:31 PM, Morten Engvoldsen 
 mortene...@gmail.comwrote:

 Hi team,
 I need to run a batch of sales records and  the batch has serial_number
 filed to store the serial number of the sales record. The serial number
 should be set to  1 everyday when the batch runs first time in a day and
 the maximum serial number could be 1000.

 So when the batch runs first time in a day and if it has 10 records, so
 the last serial number will be 10. And when the batch runs 2nd time in same
 day, the serial number should start from 11.  In this way serial_number
 will increment as an unbroken series throughout the entire working day. The
 next day when the batch runs first time the serial number will reset to 1.

 Now this could be sample code how the program can count the sequence for
 a batch:

 def salesrecord():
 serial_number = 1
 for i in selesrecord:
 print first_sales_record
 serial_number += 1
 print serial_number

 salesrecord()

 So if the batch has 10 records and last serial number of first batch is
 10, then when the batch runs second time in the same day, how the
 'serial_number' will get the value of 10 and then continue the serial
 number for the same day,  then for next day again the serial number will
 start from 1.

 Can you let me know how can i achive this in python? As i am in learning
 phase of python, can you let me know what would be good approach to do this
 in python.

 --
 http://mail.python.org/mailman/listinfo/python-list



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nuitka now supports Python 3.2

2013-02-28 Thread Stefan Behnel
Steven D'Aprano, 28.02.2013 14:23:
 On Thu, 28 Feb 2013 08:07:55 +0100, Stefan Behnel wrote:
 
 Steven D'Aprano, 26.02.2013 13:18:
 Nuitka is an implementation of Python written in C++. At the moment it
 is claimed to be about 2.5 times as fast as CPython running the pystone
 benchmark.

 Could we please get to the habit of not citing results of benchmarks
 that *any* static analysis phase will just optimise away either
 completely or in major parts?
 
 Are you saying that the pystone benchmark contains such an empty loop?
 
 Do you know for a fact that Nuitka performs such an optimization based on 
 static analysis?
 
 Are you saying that this one test is so significant that it invalidates 
 the entire pystone benchmark?

Yes, this effect renders most of the benchmark (and of similar
benchmarks) useless, and yes, Nuitka obviously does static analysis (it's
a static compiler), just like the C++ compiler that passes over the
generated code right afterwards. It's nothing special. In fact, CPython is
special in that it (deliberately) does not apply this kind of
optimisations. Everyone else does, not so much because it's required but
because it's so simple to do when you need static analysis anyway in order
to do whatever kind of static code translation. And any static compiler
needs to do static analysis, at least to some extent.

The problem with this kind of benchmarks is that they were written for
CPython and are entirely based on the assumption that the runtime does not
apply any optimisations. As soon as this assumption fails, the benchmarks
are no longer meaningful. Specifically, they are completely useless for
comparing different runtimes.

In Cython, we even deliberately do *not* implement several possible
optimisations because we know that they would only apply to bad
benchmarks, not to real-world code, and would thus only bloat our
compiler code more than they would help anyone. It's important to find a
good balance between complexity and performance, and I actually find that
CPython has made a very reasonable choice here. Its implementation is
intentionally simple in many aspects (especially its VM), and less so in
others (e.g. data types).

Stefan


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with continous incrementing of unbroken sequence for a entire working day

2013-02-28 Thread Matt Jones
Store the day as well as the serial_number in your file.  If the day is the
same as today's day, use the serial_number, if not, use 1.  At the end of
you program write the current day and serial_number.

*Matt Jones*


On Thu, Feb 28, 2013 at 1:00 PM, Morten Engvoldsen mortene...@gmail.comwrote:

 Hi,
 thanks for youe suggestion. I think i will go for your second option:

 # Runs this loop until killed
 while True
 do some stuff: clean serial_number, if day changed, calculate salesrecord
 etc.

 serial_number = salesrecord(serial_number)


 But, if i save the serial_ number value in file, then how  will it decide
 to reset the serial number to '1' when the batch  runs on next working day.
 What condition can be good, so that next day when the batch runs, it will
 know it has to reset the value 1.  Also my batch will not automatcilly run
 whole day, this is user's decision how many times he wants to run the batch
 in a day. Can you elebrate more how can i do that ...

 On Thu, Feb 28, 2013 at 6:43 PM, Vytas D. vytasd2...@gmail.com wrote:

 Hi,

 If you want to have one program running forever and printing
 sales_records, you would do (one of the possibilities) something like this:
 def salesrecord(serial_number):

 for i in salesrecord:

 print first_sales_record
 serial_number += 1
 print serial_number
 return serial_number

 if __name__ == '__main__':
 serial_number = 1

 # Runs this loop until killed
 while True
 do some stuff: clean serial_number, if day changed, calculate
 salesrecord etc.

 serial_number = salesrecord(serial_number)

 If you want to run your script so it finishes and then saves last value
 of serial_number, so you can pass it to your script when it runs next time,
 you should save the value to some file and read that file on every start of
 your program.

 Vytas


 On Thu, Feb 28, 2013 at 4:31 PM, Morten Engvoldsen 
 mortene...@gmail.comwrote:

 Hi team,
 I need to run a batch of sales records and  the batch has serial_number
 filed to store the serial number of the sales record. The serial number
 should be set to  1 everyday when the batch runs first time in a day and
 the maximum serial number could be 1000.

 So when the batch runs first time in a day and if it has 10 records, so
 the last serial number will be 10. And when the batch runs 2nd time in same
 day, the serial number should start from 11.  In this way serial_number
 will increment as an unbroken series throughout the entire working day. The
 next day when the batch runs first time the serial number will reset to 1.

 Now this could be sample code how the program can count the sequence for
 a batch:

 def salesrecord():
 serial_number = 1
 for i in selesrecord:
 print first_sales_record
 serial_number += 1
 print serial_number

 salesrecord()

 So if the batch has 10 records and last serial number of first batch is
 10, then when the batch runs second time in the same day, how the
 'serial_number' will get the value of 10 and then continue the serial
 number for the same day,  then for next day again the serial number will
 start from 1.

 Can you let me know how can i achive this in python? As i am in learning
 phase of python, can you let me know what would be good approach to do this
 in python.

 --
 http://mail.python.org/mailman/listinfo/python-list




 --
 http://mail.python.org/mailman/listinfo/python-list


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import web content to csv only if values are different from those of an excel sheet

2013-02-28 Thread Joel Goldstick
On Thu, Feb 28, 2013 at 12:25 PM, io mar...@libero.it wrote:

 Hi,

 i have the following python script that reads json data from a website
 and writes it in a csv file that i will then import to excel. (i have
 just started since a week with py so i'm a noob!) :
 ---

 import json
 import urllib
 import csv

 url = http://bitcoincharts.com/t/markets.json;
 response = urllib.urlopen(url);
 data = json.loads(response.read())

 f = open(/home/io/markets.csv,wb)
 c = csv.writer(f)

 # write headers
 c.writerow([Currency,Symbol,Bid, Ask, Volume])

 for d in data :
 if d[currency]  SLL:  #esclude la valuta di secondlife SLL
 if d[bid] is not None and d[ask] is not None:
 c.writerow([str(d[currency]),str(d[symbol]),str(d
 [bid]),str(d[ask]),str(d[currency_volume])])

 --

 I have an .ods file (libre calc - i'm on linux) where i have in a sheet
 called exclusions a list of names (symbol) the i want to exclude during
 the import from web.


If you could output this file as csv you don't have a difficult problem.
If you can't, I found this:
http://stackoverflow.com/questions/4745024/spreadsheet-to-python-dictionary-conversion
which discusses reading ods files.


 I would like to modify my script so that it can parse each row in the
 exclusion sheet and if symbol  = parsed row value then don't write
 it to the csv file ... to loop on all values in the exclusion sheet.

 I know it's certainly possible but i don't know how to do that.  (if it
 results easier having the exclusion list in a text file it's not a
 problem, i'm not really stuck with librecalc!)

 Thanks in advance to any helpful soul!  :-)
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with continous incrementing of unbroken sequence for a entire working day

2013-02-28 Thread Rick Johnson
On Thursday, February 28, 2013 10:31:58 AM UTC-6, Morten Engvoldsen wrote:
 [...]
 So if the batch has 10 records and last serial number of
 first batch is 10, then when the batch runs second time in
 the same day, how the 'serial_number' will get the value
 of 10 and then continue the serial number for the same
 day,  then for next day again the serial number will start
 from 1.


Well you need data persistence between successive runs of the program. That 
means saving some information to disc. If you don't know how to read and write 
files with Python, this might be a good time to learn!

  http://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files

But not only must you save the current serial number, you also need to save the 
current time. Here are the steps your program must do to solve this problem.

1. Run the program.

2. Read the persistent file into memory.

3. Convert the time and serial number into objects (this requires you set up an 
initial file or have your program logic invent the needed data in the absence 
of the file).

4. Find out todays date and time (modules: time and datetime would be helpful 
here).

5. Decide if the last saved date is in the range of today (these are rules 
you need to decide on before hand. Maybe a day is in the range from 12:00am to 
11:59pm... up to you).

5a. if the saved serial number was saved today, then start counting from the 
saved serial number plus 1.
5b. if however the saved serial number was saved on a previous day, then start 
counting from 1.

6. Run through all the sales records and do whatever it is you do with them.

7. Overwrite the persistent file with the newly incremented serial number and 
current time

8. Close the program cleanly.

9. Celebrate another good day of sales (well hopefully)

-- 
http://mail.python.org/mailman/listinfo/python-list


Read csv file and create a new file

2013-02-28 Thread io
Hi,

i have to files. 

First file is a csv file
Second file is a plain text file where each row has a value (text)

I want to be able to create a third file using data from the first file 
excluding the values listed in the second file.

Example:

First file:
---

mtgoxeur12  24  36
mtgoxusd10  12  14
mtgoxpln2   4   6


Second file:


mtgoxusd



Third File (the resulting one) :


mtgoxeur12  24  36
mtgoxpln2   4   6



Thanks to anyone that can help


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with continous incrementing of unbroken sequence for a entire working day

2013-02-28 Thread John Gordon
In mailman.2663.1362078015.2939.python-l...@python.org Morten Engvoldsen 
mortene...@gmail.com writes:

 But, if i save the serial_ number value in file, then how  will it decide
 to reset the serial number to '1' when the batch  runs on next working day.

Name the file so that it contains the date, i.e. serial_numbers.2013-02-28.

If the file exists, you know that the program has already run today and
you can read the file to obtain the previous serial number.

If the file does not exist, you know the program has not yet run today
and you can start the serial number at 1.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read csv file and create a new file

2013-02-28 Thread Joel Goldstick
On Thu, Feb 28, 2013 at 2:14 PM, io mar...@libero.it wrote:

 Hi,

 i have to files.

 First file is a csv file
 Second file is a plain text file where each row has a value (text)


Read the second file so that you have a list of each of its values

Read the first file line by line.  Check if the value at the beginning of
the line is in the list of values from the second file.  If not, print it
to outfile.

You should look up split method on strings to split a string separated by
whitespace.


 I want to be able to create a third file using data from the first file
 excluding the values listed in the second file.

 Example:

 First file:
 ---

 mtgoxeur12  24  36
 mtgoxusd10  12  14
 mtgoxpln2   4   6


 Second file:
 

 mtgoxusd



 Third File (the resulting one) :
 

 mtgoxeur12  24  36
 mtgoxpln2   4   6



 Thanks to anyone that can help


 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read csv file and create a new file

2013-02-28 Thread Neil Cerutti
On 2013-02-28, io mar...@libero.it wrote:
 Hi,

 i have to files. 

 First file is a csv file
 Second file is a plain text file where each row has a value (text)

 I want to be able to create a third file using data from the first file 
 excluding the values listed in the second file.

 Example:

 First file:
 ---

 mtgoxeur  12  24  36
 mtgoxusd  10  12  14
 mtgoxpln  2   4   6


 Second file:
 

 mtgoxusd



 Third File (the resulting one) :
 

 mtgoxeur  12  24  36
 mtgoxpln  2   4   6

 Thanks to anyone that can help

You don't appear to need the csv module at all. You'll just need
the startswith string function.

For more help, please show us some code.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read csv file and create a new file

2013-02-28 Thread Dave Angel

On 02/28/2013 02:14 PM, io wrote:

Hi,

i have to files.

First file is a csv file
Second file is a plain text file where each row has a value (text)

I want to be able to create a third file using data from the first file
excluding the values listed in the second file.

Example:

First file:
---

mtgoxeur12  24  36
mtgoxusd10  12  14
mtgoxpln2   4   6


Second file:


mtgoxusd



Third File (the resulting one) :


mtgoxeur12  24  36
mtgoxpln2   4   6



Thanks to anyone that can help





Start by making a set out of the second file.  Don't forget to remove 
whitespace with strip()


Then loop through the first file.  For each line, split() it by 
whitespace, and conditionally write the line to the third file.  The 
test would be something like:

 if  fields[0] in myset:
   outfile.write(line)


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


suggestions for improving code fragment please

2013-02-28 Thread The Night Tripper
Hi there
I'm being very dumb ... how can I simplify this fragment?


if arglist:
arglist.pop(0)
if arglist:
self.myparm1 = arglist.pop(0)
if arglist:
self.myparm2 = arglist.pop(0)
if arglist:
self.myparm3 = arglist.pop(0)
if arglist:
self.parm4 = arglist.pop(0)
# ...

Thanks
J^n


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read csv file and create a new file

2013-02-28 Thread io
I'm a noob in python but my code looks like this :


import json
import urllib
import csv

url = http://bitcoincharts.com/t/markets.json;
response = urllib.urlopen(url);
data = json.loads(response.read())

f = open(/home/io/markets.csv,wb)
c = csv.writer(f)

#apre un file di testo e legge il contenuto del file inserendolo in una 
stringa
esclusioni = open('/home/io/exclusions.txt','r')
string = 
while 1:
line = esclusioni.readline()
if not line:break
string += line
print string



# write headers
c.writerow([Currency,Symbol,Bid, Ask, Volume])

for d in data :
if d[currency]  SLL:  #esclude la valuta di secondlife SLL
if d[bid] is not None and d[ask] is not None:
if not any(str(d[symbol]) in s for s in string):
c.writerow([str(d[currency]),str(d[symbol]),str(d
[bid]),str(d[ask]),str(d[currency_volume])])

esclusioni.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions for improving code fragment please

2013-02-28 Thread Ian Kelly
On Thu, Feb 28, 2013 at 12:47 PM, The Night Tripper jkn...@nicorp.co.uk wrote:
 Hi there
 I'm being very dumb ... how can I simplify this fragment?


 if arglist:
 arglist.pop(0)
 if arglist:
 self.myparm1 = arglist.pop(0)
 if arglist:
 self.myparm2 = arglist.pop(0)
 if arglist:
 self.myparm3 = arglist.pop(0)
 if arglist:
 self.parm4 = arglist.pop(0)

Perhaps this would work for you:

if arglist:
defaults = [self.parm1, self.parm2, self.parm3, self.parm4]
arglist = arglist[1:] + defaults[len(arglist)-1:]
self.parm1, self.parm2, self.parm3, self.parm4 = arglist[:4]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions for improving code fragment please

2013-02-28 Thread Joel Goldstick
On Thu, Feb 28, 2013 at 2:47 PM, The Night Tripper jkn...@nicorp.co.ukwrote:

 Hi there
 I'm being very dumb ... how can I simplify this fragment?

i = 0
while arglist:
self.myparm[i] = arglist.pop(0)
i += 1



 if arglist:
 arglist.pop(0)
 if arglist:
 self.myparm1 = arglist.pop(0)
 if arglist:
 self.myparm2 = arglist.pop(0)
 if arglist:
 self.myparm3 = arglist.pop(0)
 if arglist:
 self.parm4 = arglist.pop(0)
 # ...

 Thanks
 J^n


 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions for improving code fragment please

2013-02-28 Thread Rick Johnson
On Thursday, February 28, 2013 1:47:12 PM UTC-6, The Night Tripper wrote:
 I'm being very dumb ... how can I simplify this fragment?
 
 if arglist:
 arglist.pop(0)
 if arglist:
 self.myparm1 = arglist.pop(0)
 if arglist:
 self.myparm2 = arglist.pop(0)
 if arglist:
 self.myparm3 = arglist.pop(0)
 if arglist:
 self.parm4 = arglist.pop(0)

Depends. If the length of arglist is known you could simply unpack it:

  a,b,c,d = (1,2,3,4)

If the length is unknown, a while loop would do the trick. All you need is to 
figure out what truth condition to test for on each iteration of the while 
loop.

 while truthCondition:
#assign variable to value
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read csv file and create a new file

2013-02-28 Thread Neil Cerutti
On 2013-02-28, io mar...@libero.it wrote:
 I'm a noob in python but my code looks like this :


 import json
 import urllib
 import csv

I take back what I said about the csv module. It appears you need
access to at least one of the data fields, so this is a good use
of csv.

 url = http://bitcoincharts.com/t/markets.json;
 response = urllib.urlopen(url);
 data = json.loads(response.read())

 f = open(/home/io/markets.csv,wb)
 c = csv.writer(f)

 #apre un file di testo e legge il contenuto del file inserendolo in una 
 stringa
 esclusioni = open('/home/io/exclusions.txt','r')
 string = 

The list of exclusions should be stored in a set or list, not a
string. This is your main bug.

esclusioni_file = open('/home/io/exclusions.txt','r')
esclusioni = []

 while 1:
 line = esclusioni.readline()
 if not line:break
 string += line
 print string

Iterate over the file instead of looping manually.

 for line in esclusioni_file:
 esclusioni.append(line.strip())
 print(esclusioni)

 # write headers
 c.writerow([Currency,Symbol,Bid, Ask, Volume])

 for d in data:
 if d[currency]  SLL:  #esclude la valuta di secondlife SLL
 if d[bid] is not None and d[ask] is not None:
 if not any(str(d[symbol]) in s for s in string):

Why are you checking d[symbol] instead of d[currency]? Maybe
I misunderstood the question.

Test like this for either set or list container type. Use
whichever json field is appropriate:

  if d[currency] not in esclusioni:

 c.writerow([str(d[currency]),str(d[symbol]),str(d
 [bid]),str(d[ask]),str(d[currency_volume])])
 
 esclusioni.close()

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read csv file and create a new file

2013-02-28 Thread io

 Iterate over the file instead of looping manually.
 
  for line in esclusioni_file:
  esclusioni.append(line.strip())
  print(esclusioni)

the print was only to see if it was reading correct data but iìm not 
needing to see it.

 
 Why are you checking d[symbol] instead of d[currency]? Maybe I
 misunderstood the question.

the file esclusioni.txt has the names of the market places that i want to 
exclude ... the correspoding marketplace name is found in the symbol 
value of the json imported data, that's why i'm comparing it with symbol.



 Test like this for either set or list container type. Use whichever json
 field is appropriate:
 
   if d[currency] not in esclusioni:
 
 c.writerow([str(d[currency]),str(d[symbol]),str(d
 [bid]),str(d[ask]),str(d[currency_volume])])
 
 esclusioni.close()

that's a nice approach ( if d[symbol] not in esclusioni: )!!!

Thanks i will give it a try ... i was getting crazy and my mind was 
looping dangerously!  :-)

-- 
http://mail.python.org/mailman/listinfo/python-list


Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread kramer65
Hello,

I'm using Python for a while now and I love it. There is just one thing I 
cannot understand. There are compilers for languages like C and C++. why is it 
impossible to create a compiler that can compile Python code to machinecode?

My reasoning is as follows:
When GCC compiles a program written in C++, it simply takes that code and 
decides what instructions that would mean for the computer's hardware. What 
does the CPU need to do, what does the memory need to remember, etc. etc. If 
you can create this machinecode from C++, then I would suspect that it should 
also be possible to do this (without a C-step in between) for programs written 
in Python.

Where is my reasoning wrong here? Is that because Python is dynamically typed? 
Does machinecode always need to know whether a variable is an int or a float? 
And if so, can't you build a compiler which creates machinecode that can handle 
both ints and floats in case of doubt? Or is it actually possible to do, but so 
much work that nobody does it?

I googled around, and I *think* it is because of the dynamic typing, but I 
really don't understand why this would be an issue..

Any insights on this would be highly appreciated!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions for improving code fragment please

2013-02-28 Thread Tim Chase
On 2013-02-28 19:47, The Night Tripper wrote:
 Hi there
 I'm being very dumb ... how can I simplify this fragment?
 
 
 if arglist:
 arglist.pop(0)
 if arglist:
 self.myparm1 = arglist.pop(0)
 if arglist:
 self.myparm2 = arglist.pop(0)
 if arglist:
 self.myparm3 = arglist.pop(0)
 if arglist:
 self.parm4 = arglist.pop(0)

If they're arbitrarily named attributes of the self, you could do
something like

  for attr in (myparm1, myparm2, myparm3, ...):
if arglist:
  setattr(self, attr, arglist.pop(0))
else:
  break

-tkc



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-28 Thread Chris Angelico
On Fri, Mar 1, 2013 at 5:28 AM, Rick Johnson
rantingrickjohn...@gmail.com wrote:
 Q: Do you feel that the bug tracker should be a place where users discuss 
 grievances that distract volunteers from fixing actual bugs?

So you admit that discussion of your whining about perceived
grievances would distract busy people from doing useful things to and
with Python... and yet you demand GvR's *personal* involvement. I
think you grossly misunderstand the position of BDFL. It's servant to
all, but not grovelling, boot-licking sap with no life who spends
all day dealing with idiots. A subtle difference, I'm sure, and I can
understand how someone of your intellect could fail to recognize it.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: Issue with continous incrementing of unbroken sequence for a entire working day

2013-02-28 Thread Morten Engvoldsen
Hi,
Okey i have wrote the below program as you suggested:

import time
from datetime import date

def salesrecord():
serial_number = 0
sales_recrod = {'record1':'product1',
'record2':'product2','record3':'product3'}
for i in sales_recrod:
print sales_recrod[i]
serial_number += 1
print serial_number
fo = open(workfile.txt, wb)
fo.write(str(serial_number))
fo.close()
with open(workfile.txt, 'r') as f:
serial_number = f.read()
today = date.today()



salesrecord()


Here i am bit confuse with where i should write the read file function to
read the current serial number and date. also when i overwrite the file
with current serial number, it will overwrite the date also with current
date, in that case how will i  compare the date. Can you please show me in
my example how can i achive this..


-- Forwarded message --
From: Matt Jones matt.walker.jo...@gmail.com
To: python-list@python.org python-list@python.org
Cc:
Date: Thu, 28 Feb 2013 13:11:38 -0600
Subject: Re: Issue with continous incrementing of unbroken sequence for a
entire working day
Store the day as well as the serial_number in your file.  If the day is the
same as today's day, use the serial_number, if not, use 1.  At the end of
you program write the current day and serial_number.

*Matt Jones*


On Thu, Feb 28, 2013 at 1:00 PM, Morten Engvoldsen mortene...@gmail.comwrote:
Hi,
thanks for youe suggestion. I think i will go for your second option:

# Runs this loop until killed
while True
do some stuff: clean serial_number, if day changed, calculate salesrecord
etc.

serial_number = salesrecord(serial_number)


But, if i save the serial_ number value in file, then how  will it decide
to reset the serial number to '1' when the batch  runs on next working day.
What condition can be good, so that next day when the batch runs, it will
know it has to reset the value 1.  Also my batch will not automatcilly run
whole day, this is user's decision how many times he wants to run the batch
in a day. Can you elebrate more how can i do that ...

-- Forwarded message --
From: Morten Engvoldsen mortene...@gmail.com
Date: Thu, Feb 28, 2013 at 5:31 PM
Subject: Issue with continous incrementing of unbroken sequence for a
entire working day
To: python-list@python.org


Hi team,
I need to run a batch of sales records and  the batch has serial_number
filed to store the serial number of the sales record. The serial number
should be set to  1 everyday when the batch runs first time in a day and
the maximum serial number could be 1000.

So when the batch runs first time in a day and if it has 10 records, so the
last serial number will be 10. And when the batch runs 2nd time in same
day, the serial number should start from 11.  In this way serial_number
will increment as an unbroken series throughout the entire working day. The
next day when the batch runs first time the serial number will reset to 1.

Now this could be sample code how the program can count the sequence for a
batch:

def salesrecord():
serial_number = 1
for i in selesrecord:
print first_sales_record
serial_number += 1
print serial_number

salesrecord()

So if the batch has 10 records and last serial number of first batch is 10,
then when the batch runs second time in the same day, how the
'serial_number' will get the value of 10 and then continue the serial
number for the same day,  then for next day again the serial number will
start from 1.

Can you let me know how can i achive this in python? As i am in learning
phase of python, can you let me know what would be good approach to do this
in python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read csv file and create a new file

2013-02-28 Thread io
Neil, it works great!

Just one question : what can i do for ignoring the case sensitive of the 
symbol?

It wasn't working initially, then i wrote the values respecting case 
sensitive in the file esclusioni and all worked as a charm. I would just 
like to know if i could ignore the case senstive function.

Thanks alot for your help.

I'm in debt with you, i'll spend a pizza for you!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread Matty Sarro
Python is an interpreted language, not a compiled language. This is
actually a good thing! What it means is that there is a scripting engine
(we just call it the interpreter) that actually executes everything for
you. That means that any operating system that has an interpreter written
for it is capable of running the exact same code (there are lots of
exceptions to this, but in general it is true). It makes code much more
portable. Also, it makes it easy to troubleshoot (compiled programs are a
pain in the butt unless you add additional debugging elements to them).

A compiled program on the other hand must be specifically compiled for the
destination architecture (so if you're trying to write an OSX executable on
windows, you need a compiler capable of doing that). So doing any sort of
cross platform development can take significantly longer. Plus then, as I
said, debugging will require additional debug tracing elements to be added
to the code you write. The benefit though is that compilers can optimize
code for you when they compile, and the compiled code will tend to run
faster since you're not dealing with an interpreter between you and the
machine.

Now, there are places where this line is blurred. For instance perl is an
interpreted language, but capable of running EXTREMELY fast. Python is a
little slower, but significantly easier to read and write than perl. You
also have some weird ones like JAVA which actually have a virtual machine,
and half compile source code into java bytecode. This is then executed
by the virtual machine.

I guess the ultimate point is that they're all designed for different
purposes, and to solve different problems. Python was intended to make
fast-to-write, easily understandable, easily portable code which can be
executed on any system which has the Python interpreter. It's not really
intended for things which require lower level access to hardware. It's what
we call a high level programming language.

C (your example) was intended for very low level programming, things like
operating systems, device drivers, networking stacks, where the speed of a
compiled executable and direct access to hardware was a necessity. That's
what Dennis Ritchie wrote it for. We call it a mid level programming
language, or a low level programming language depending on who you talk
to. I'd have to say mid level because low level would be writing in
assembly or playing with a hex editor :)

Different tools for different jobs.

HTH.

-Matty


On Thu, Feb 28, 2013 at 3:25 PM, kramer65 kram...@gmail.com wrote:

 Hello,

 I'm using Python for a while now and I love it. There is just one thing I
 cannot understand. There are compilers for languages like C and C++. why is
 it impossible to create a compiler that can compile Python code to
 machinecode?

 My reasoning is as follows:
 When GCC compiles a program written in C++, it simply takes that code and
 decides what instructions that would mean for the computer's hardware. What
 does the CPU need to do, what does the memory need to remember, etc. etc.
 If you can create this machinecode from C++, then I would suspect that it
 should also be possible to do this (without a C-step in between) for
 programs written in Python.

 Where is my reasoning wrong here? Is that because Python is dynamically
 typed? Does machinecode always need to know whether a variable is an int or
 a float? And if so, can't you build a compiler which creates machinecode
 that can handle both ints and floats in case of doubt? Or is it actually
 possible to do, but so much work that nobody does it?

 I googled around, and I *think* it is because of the dynamic typing, but I
 really don't understand why this would be an issue..

 Any insights on this would be highly appreciated!

 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with continous incrementing of unbroken sequence for a entire working day

2013-02-28 Thread Chris Angelico
On Fri, Mar 1, 2013 at 6:23 AM, John Gordon gor...@panix.com wrote:
 In mailman.2663.1362078015.2939.python-l...@python.org Morten Engvoldsen 
 mortene...@gmail.com writes:

 But, if i save the serial_ number value in file, then how  will it decide
 to reset the serial number to '1' when the batch  runs on next working day.

 Name the file so that it contains the date, i.e. serial_numbers.2013-02-28.

 If the file exists, you know that the program has already run today and
 you can read the file to obtain the previous serial number.

 If the file does not exist, you know the program has not yet run today
 and you can start the serial number at 1.

Probably overkill; simpler to have just one file and record the date.
Just be careful of definitions - do you use the current date UTC or
the current date local time? And be aware of what might happen if the
local clock is changed.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read csv file and create a new file

2013-02-28 Thread io
The final working code is :

import json
import urllib
import csv

url = http://bitcoincharts.com/t/markets.json;
response = urllib.urlopen(url);
data = json.loads(response.read())

f = open(/home/io/markets.csv,wb)
c = csv.writer(f)

#apre un file di testo e legge il contenuto del file inserendolo in una 
stringa
esclusioni_file = open('/home/io/exclusions.txt','r')
esclusioni = []

for line in esclusioni_file:
 esclusioni.append(line.strip())
#print(esclusioni)


# write headers
c.writerow([Currency,Symbol,Bid, Ask, Volume])

for d in data :
if d[currency]  SLL:  #esclude la valuta di secondlife SLL
if d[bid] is not None and d[ask] is not None:
if d[symbol] not in esclusioni:
#print d[symbol]
c.writerow([str(d[currency]),str(d[symbol]),str(d
[bid]),str(d[ask]),str(d[currency_volume])])
#esclusioni.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread Stefan Behnel
kramer65, 28.02.2013 21:25:
 I'm using Python for a while now and I love it. There is just one thing
 I cannot understand. There are compilers for languages like C and C++.
 why is it impossible to create a compiler that can compile Python code
 to machinecode?

All projects that implement such compilers prove that it's quite possible.

The most widely used static Python compiler is Cython, but there are also a
couple of experimental compilers that do similar things in more or less
useful or usable ways. And there are also a couple of projects that do
dynamic runtime compilation, most notably PyPy and Numba.

You may want to take a look at the Python implementations page,
specifically the list of Python compilers:

http://wiki.python.org/moin/PythonImplementations#Compilers


 Does machinecode always need to know whether a variable is an int or a 
 float?

Not at all. You're mixing different levels of abstraction here.


 And if so, can't you build a compiler which creates machinecode 
 that can handle both ints and floats in case of doubt?

Sure. Cython does just that, for example, unless you tell it explicitly to
restrict a variable to a specific type. Basically, you get Python semantics
by default and C semantics if you want to.

Stefan

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with continous incrementing of unbroken sequence for a entire working day

2013-02-28 Thread Rick Johnson
On Thursday, February 28, 2013 2:41:30 PM UTC-6, Morten Engvoldsen wrote:

 [...]

 def salesrecord():
     serial_number = 0
     sales_recrod = {'record1':'product1',
 'record2':'product2',
 'record3':'product3',
 }
 
     for i in sales_recrod:
     print sales_recrod[i]
     serial_number += 1
     print serial_number
     fo = open(workfile.txt, wb)
     fo.write(str(serial_number))
     fo.close()
 
     with open(workfile.txt, 'r') as f:
     serial_number = f.read()
     today = date.today()


I would highly suggest breaking this code into a few specific functions:

def main()
def readDataFile()
def writeDataFile()
def computeDates()
def processSalesRecord()

and then run main from this:

if __name__ == '__main__':
main()

PS: Please trim superfluous quotes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread Chris Angelico
On Fri, Mar 1, 2013 at 7:50 AM, Matty Sarro msa...@gmail.com wrote:
 C (your example) was intended for very low level programming, things like
 operating systems, device drivers, networking stacks, where the speed of a
 compiled executable and direct access to hardware was a necessity. That's
 what Dennis Ritchie wrote it for. We call it a mid level programming
 language, or a low level programming language depending on who you talk
 to. I'd have to say mid level because low level would be writing in assembly
 or playing with a hex editor :)

Assembly is for people who write C compilers.
C is for people who write language interpreters/compilers.
Everyone else uses a high level language.

Not 100% accurate but a reasonable rule of thumb.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions for improving code fragment please

2013-02-28 Thread MRAB

On 2013-02-28 19:47, The Night Tripper wrote:

Hi there
 I'm being very dumb ... how can I simplify this fragment?


 if arglist:
 arglist.pop(0)
 if arglist:
 self.myparm1 = arglist.pop(0)
 if arglist:
 self.myparm2 = arglist.pop(0)
 if arglist:
 self.myparm3 = arglist.pop(0)
 if arglist:
 self.parm4 = arglist.pop(0)
 # ...


You could just catch the exception:

try:
arglist.pop(0)
self.myparm1 = arglist.pop(0)
self.myparm2 = arglist.pop(0)
self.myparm3 = arglist.pop(0)
self.parm4 = arglist.pop(0)
except IndexError:
pass

--
http://mail.python.org/mailman/listinfo/python-list


Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread Stefan Behnel
Stefan Behnel, 28.02.2013 22:03:
 there are also a couple of projects that do
 dynamic runtime compilation, most notably PyPy and Numba.

Oh, and HotPy, I keep forgetting about that.

 You may want to take a look at the Python implementations page,
 specifically the list of Python compilers:
 
 http://wiki.python.org/moin/PythonImplementations#Compilers

Stefan


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread Dave Angel

On 02/28/2013 03:25 PM, kramer65 wrote:

Hello,

I'm using Python for a while now and I love it. There is just one thing I 
cannot understand. There are compilers for languages like C and C++. why is it 
impossible to create a compiler that can compile Python code to machinecode?

My reasoning is as follows:
When GCC compiles a program written in C++, it simply takes that code and 
decides what instructions that would mean for the computer's hardware. What 
does the CPU need to do, what does the memory need to remember, etc. etc. If 
you can create this machinecode from C++, then I would suspect that it should 
also be possible to do this (without a C-step in between) for programs written 
in Python.

Where is my reasoning wrong here? Is that because Python is dynamically typed? 
Does machinecode always need to know whether a variable is an int or a float? 
And if so, can't you build a compiler which creates machinecode that can handle 
both ints and floats in case of doubt? Or is it actually possible to do, but so 
much work that nobody does it?

I googled around, and I *think* it is because of the dynamic typing, but I 
really don't understand why this would be an issue..

Any insights on this would be highly appreciated!



Sure, python could be compiled into machine code.  But what machine?  Do 
you refer to the hardware inside one of the Pentium chips?  Sorry, but 
Intel doesn't expose those instructions to the public.  Instead, they 
wrote a microcode interpreter, and embedded it inside their processor, 
and the machine languages that are documented as the Pentium 
Instruction sets are what that interpreter handles.  Good thing too, as 
the microcode machine language has changed radically over time, and I'd 
guess there have been at least a dozen major variants, and a hundred 
different sets of details.


So if we agree to ignore that interpreter, and consider the externally 
exposed machine language, we can pick a subset of the various such 
instruction sets, and make that our target.


Can Python be compiled directly into that instruction set?  Sure, it 
could.  But would it be practical to write a compiler that went directly 
to it, or is it simpler to target C, and use gcc?


Let's look at gcc.  When you run it, does it look like it compiles C 
directly to machine language?  Nope.  It has 3 phases (last I looked, 
which was admittedly over 20 years ago).  The final phase translates an 
internal form of program description into a particular machine 
language.  Even the mighty gcc doesn't do it in one step.  Guess what, 
that means other languages can use the same back end, and a given 
language can use different back ends for different target machine 
languages.  (Incidentally, Microsoft C compiler does the exact same 
thing, and a few of my patents involve injecting code between front end 
and back end)


So now we have three choices.  We could target the C language, and use 
all of gcc, or we could target the intermediate language, and use only 
the backend of gcc.   Unfortunately, that intermediate language isn't 
portable between compilers, so you'd either have to write totally 
separate python compilers for each back end, or skip that approach, or 
abandon total portability.


Well, we could write a Python compiler that targets an abstract 
intermediate language, which in turn gets translated into each of the 
supported compiler's intermediate language.  But that gets remarkably 
close to just targeting C in the first place.


So how hard would it be just to directly target one machine language? 
Not too bad if you didn't try to do any optimizations, or adapt to the 
different quirks and missing features of the different implementations 
of that machine language.  But I expect what you got would be neither 
smaller nor noticeably faster than the present system.  Writing simple 
optimizations that improve some things is easy.  Writing great 
optimizers that are also reliable and correct is incredibly hard.  I'd 
expect that gcc has hundreds of man years of effort in it.


Now, no matter which of these approaches you would take, there are some 
issues.  The tricky part is not being flexible between int and float 
(and long, which is not part of the Intel machine instruction set), but 
between an unlimited set of possible meanings for each operation.  Just 
picking on  a+b, each class type that a and b might be can provide their 
own __add__ and/or __radd__ methods.  All those have to be searched for, 
one has to be picked, and the code has to branch there.  And that 
decision, in general, has to be made at runtime, not by the compiler.


So by default, the code ends up being a twisted set of 4way 
indirections, calls to dict lookups, and finally calling a function that 
actually does an instruction or two of real work.  Guess what, an 
interpreter can store those details much more succinctly (code size), 
and can run those choices nearly as quickly.  So we're back to CPython.


Could it be 

Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread Modulok
 I'm using Python for a while now and I love it. There is just one thing I
 cannot understand. There are compilers for languages like C and C++. why is
 it impossible to create a compiler that can compile Python code to
 machinecode?

Not exactly what you describe, but have you checked out PyPy?

http://pypy.org/


-Modulok-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions for improving code fragment please

2013-02-28 Thread Mitya Sirenef

On 02/28/2013 02:47 PM, The Night Tripper wrote:

Hi there

 I'm being very dumb ... how can I simplify this fragment?


 if arglist:
 arglist.pop(0)
 if arglist:
 self.myparm1 = arglist.pop(0)
 if arglist:
 self.myparm2 = arglist.pop(0)
 if arglist:
 self.myparm3 = arglist.pop(0)
 if arglist:
 self.parm4 = arglist.pop(0)
 # ...

 Thanks
 J^n




I often use this convenience function:

def getitem(seq, index, default=None):
Get item from an `seq` at `index`, return default if index out of 
range.

try : return seq[index]
except IndexError : return default


If you're ok with setting myparm values to default None, you can do:

self.myparm1, self.myparm2, self.myparm3, self.myparm4 = \
(getitem(arglist, n) for n in range(4))


If you only want to set them when they are in arglist:

for n in range(4):
val = getitem(arglist, n)
if val is not None:
setattr(self, myparm%d % (n+1), val)

-m



--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

“So many books, so little time.”
― Frank Zappa

--
http://mail.python.org/mailman/listinfo/python-list


Re: Read csv file and create a new file

2013-02-28 Thread Dave Angel

On 02/28/2013 03:46 PM, io wrote:

Neil, it works great!

Just one question : what can i do for ignoring the case sensitive of the
symbol?

It wasn't working initially, then i wrote the values respecting case
sensitive in the file esclusioni and all worked as a charm. I would just
like to know if i could ignore the case senstive function.

Thanks alot for your help.

I'm in debt with you, i'll spend a pizza for you!



Just use a tolower() method on both strings when you're comparing them. 
 Of course, that may not work well with international character sets. 
Some characters in some languages have no lowercase equivalent, and 
using toupper() has the same problem in other languages.


Also, the approach to case insensitive differs between Python 2.x and 3.x


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions for improving code fragment please

2013-02-28 Thread Dave Angel

On 02/28/2013 03:37 PM, Tim Chase wrote:

On 2013-02-28 19:47, The Night Tripper wrote:

Hi there
 I'm being very dumb ... how can I simplify this fragment?


 if arglist:
 arglist.pop(0)
 if arglist:
 self.myparm1 = arglist.pop(0)
 if arglist:
 self.myparm2 = arglist.pop(0)
 if arglist:
 self.myparm3 = arglist.pop(0)
 if arglist:
 self.parm4 = arglist.pop(0)


If they're arbitrarily named attributes of the self, you could do
something like

   for attr in (myparm1, myparm2, myparm3, ...):
 if arglist:
   setattr(self, attr, arglist.pop(0))
 else:
   break

-tkc




Or something like (untested):

for name, value in zip([myparm1, myparm2, myparm3], arglist):
 setattr(self, name, value)
arglist = [] #if you care how it ends up


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions for improving code fragment please

2013-02-28 Thread Terry Reedy

On 2/28/2013 2:47 PM, The Night Tripper wrote:

Hi there
 I'm being very dumb ... how can I simplify this fragment?


 if arglist:
 arglist.pop(0)
 if arglist:
 self.myparm1 = arglist.pop(0)
 if arglist:
 self.myparm2 = arglist.pop(0)
 if arglist:
 self.myparm3 = arglist.pop(0)
 if arglist:
 self.parm4 = arglist.pop(0)


To literally do the same thing

try:
arglist.pop(0)
self.myparm1 = arglist.pop(0)
self.myparm2 = arglist.pop(0)
self.myparm3 = arglist.pop(0)
self.parm4 = arglist.pop(0)
except IndexError:
pass

However, repeated popping from the front is O(n**2) instead of O(n).
Following should do the same, including removal from original arglist.

it = iter(arglist)
n = 0
try:
next(it); n += 1
self.myparm1 = next(it); n += 1
self.myparm2 = next(it); n += 1
self.myparm3 = next(it); n += 1
self.parm4 = next(it); n += 1
except StopIteration:
pass
arglist = arglist[n:]

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread Jonas Geiregat
On do, feb 28, 2013 at 12:25:07pm -0800, kramer65 wrote:
 Hello,
 
 I'm using Python for a while now and I love it. There is just one thing I 
 cannot understand. There are compilers for languages like C and C++. why is 
 it impossible to create a compiler that can compile Python code to 
 machinecode?
 
 My reasoning is as follows:
 When GCC compiles a program written in C++, it simply takes that code and 
 decides what instructions that would mean for the computer's hardware. What 
 does the CPU need to do, what does the memory need to remember, etc. etc. If 
 you can create this machinecode from C++, then I would suspect that it should 
 also be possible to do this (without a C-step in between) for programs 
 written in Python.
 
 Where is my reasoning wrong here? Is that because Python is dynamically 
 typed? Does machinecode always need to know whether a variable is an int or a 
 float? And if so, can't you build a compiler which creates machinecode that 
 can handle both ints and floats in case of doubt? Or is it actually possible 
 to do, but so much work that nobody does it?
 
 I googled around, and I *think* it is because of the dynamic typing, but I 
 really don't understand why this would be an issue..
 
 Any insights on this would be highly appreciated!
 
Guido actually encourages people to try to build different compilers for

python. He thinks it might, one day, be possible to have a compiler for 

python. 

But this could only be possible if there was some kind of global

file based annotation saying you will not use some of the dynamic parts 

of python. Else it won't be possible to create a compiler for such a

highly dynmaic language as python.  



You can view the key-note where he talks about this here:   

http://www.youtube.com/watch?v=EBRMq2Ioxsc  



Jonas. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with continous incrementing of unbroken sequence for a entire working day

2013-02-28 Thread Morten Engvoldsen
Hi,
Thanks all for suggestion...

I am using current date as current date local time. I think
datetime.datetime will provide current local date and time, so
hopefullt the function take care
if the local clock is changed...

-- Forwarded message --
From: Chris Angelico ros...@gmail.com
To: python-list@python.org
Cc:
Date: Fri, 1 Mar 2013 07:52:04 +1100
Subject: Re: Issue with continous incrementing of unbroken sequence
for a entire working day
On Fri, Mar 1, 2013 at 6:23 AM, John Gordon gor...@panix.com wrote:
 In mailman.2663.1362078015.2939.python-l...@python.org Morten Engvoldsen 
 mortene...@gmail.com writes:

 But, if i save the serial_ number value in file, then how  will it decide
 to reset the serial number to '1' when the batch  runs on next working day.

 Name the file so that it contains the date, i.e. serial_numbers.2013-02-28.

 If the file exists, you know that the program has already run today and
 you can read the file to obtain the previous serial number.

 If the file does not exist, you know the program has not yet run today
 and you can start the serial number at 1.

Probably overkill; simpler to have just one file and record the date.
Just be careful of definitions - do you use the current date UTC or
the current date local time? And be aware of what might happen if the
local clock is changed.

ChrisA

On Thu, Feb 28, 2013 at 9:41 PM, Morten Engvoldsen mortene...@gmail.com wrote:

 Hi,
 Okey i have wrote the below program as you suggested:

 import time
 from datetime import date

 def salesrecord():
 serial_number = 0
 sales_recrod = {'record1':'product1', 
 'record2':'product2','record3':'product3'}
 for i in sales_recrod:
 print sales_recrod[i]

 serial_number += 1
 print serial_number
 fo = open(workfile.txt, wb)
 fo.write(str(serial_number))
 fo.close()
 with open(workfile.txt, 'r') as f:
 serial_number = f.read()
 today = date.today()



 salesrecord()


 Here i am bit confuse with where i should write the read file function to 
 read the current serial number and date. also when i overwrite the file with 
 current serial number, it will overwrite the date also with current date, in 
 that case how will i  compare the date. Can you please show me in my example 
 how can i achive this..


 -- Forwarded message --
 From: Matt Jones matt.walker.jo...@gmail.com
 To: python-list@python.org python-list@python.org
 Cc:
 Date: Thu, 28 Feb 2013 13:11:38 -0600
 Subject: Re: Issue with continous incrementing of unbroken sequence for a 
 entire working day
 Store the day as well as the serial_number in your file.  If the day is the 
 same as today's day, use the serial_number, if not, use 1.  At the end of you 
 program write the current day and serial_number.

 Matt Jones


 On Thu, Feb 28, 2013 at 1:00 PM, Morten Engvoldsen mortene...@gmail.com 
 wrote:
 Hi,
 thanks for youe suggestion. I think i will go for your second option:

 # Runs this loop until killed
 while True
 do some stuff: clean serial_number, if day changed, calculate salesrecord 
 etc.

 serial_number = salesrecord(serial_number)


 But, if i save the serial_ number value in file, then how  will it decide to 
 reset the serial number to '1' when the batch  runs on next working day. What 
 condition can be good, so that next day when the batch runs, it will know it 
 has to reset the value 1.  Also my batch will not automatcilly run whole day, 
 this is user's decision how many times he wants to run the batch in a day. 
 Can you elebrate more how can i do that ...

 -- Forwarded message --
 From: Morten Engvoldsen mortene...@gmail.com
 Date: Thu, Feb 28, 2013 at 5:31 PM
 Subject: Issue with continous incrementing of unbroken sequence for a entire 
 working day
 To: python-list@python.org


 Hi team,
 I need to run a batch of sales records and  the batch has serial_number filed 
 to store the serial number of the sales record. The serial number should be 
 set to  1 everyday when the batch runs first time in a day and the maximum 
 serial number could be 1000.

 So when the batch runs first time in a day and if it has 10 records, so the 
 last serial number will be 10. And when the batch runs 2nd time in same day, 
 the serial number should start from 11.  In this way serial_number will 
 increment as an unbroken series throughout the entire working day. The next 
 day when the batch runs first time the serial number will reset to 1.

 Now this could be sample code how the program can count the sequence for a 
 batch:

 def salesrecord():
 serial_number = 1
 for i in selesrecord:
 print first_sales_record
 serial_number += 1
 print serial_number

 salesrecord()

 So if the batch has 10 records and last serial number of first batch is 10, 
 then when the batch runs second time in the same day, how the 'serial_number' 
 will get the value of 10 and then continue the serial number for the 

Re: Issue with continous incrementing of unbroken sequence for a entire working day

2013-02-28 Thread Chris Angelico
On Fri, Mar 1, 2013 at 8:44 AM, Morten Engvoldsen mortene...@gmail.com wrote:
 Hi,
 Thanks all for suggestion...

 I am using current date as current date local time. I think
 datetime.datetime will provide current local date and time, so
 hopefullt the function take care
 if the local clock is changed...

The worst that can happen is that the date changes and your serial
resets when it shouldn't. Can you cope with that? (Or just blame it on
the user and let them cope?) If so, it's easy.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with continous incrementing of unbroken sequence for a entire working day

2013-02-28 Thread Morten Engvoldsen
Hi,
I think i can use Europe time zone as current local time :

import datetime as dt
 import pytz
 utc = pytz.timezone(UTC)
 norway = pytz.timezone(Europe/Norway)
 a = dt.datetime(2008, 7, 6, 5, 4, 3, tzinfo=utc)
 b = a.astimezone(norway)

i think this will provide me correct current local time when clock is changed...

On Thu, Feb 28, 2013 at 10:44 PM, Morten Engvoldsen
mortene...@gmail.com wrote:
 Hi,
 Thanks all for suggestion...

 I am using current date as current date local time. I think
 datetime.datetime will provide current local date and time, so
 hopefullt the function take care
 if the local clock is changed...

 -- Forwarded message --
 From: Chris Angelico ros...@gmail.com
 To: python-list@python.org
 Cc:
 Date: Fri, 1 Mar 2013 07:52:04 +1100
 Subject: Re: Issue with continous incrementing of unbroken sequence
 for a entire working day
 On Fri, Mar 1, 2013 at 6:23 AM, John Gordon gor...@panix.com wrote:
 In mailman.2663.1362078015.2939.python-l...@python.org Morten Engvoldsen 
 mortene...@gmail.com writes:

 But, if i save the serial_ number value in file, then how  will it decide
 to reset the serial number to '1' when the batch  runs on next working day.

 Name the file so that it contains the date, i.e. serial_numbers.2013-02-28.

 If the file exists, you know that the program has already run today and
 you can read the file to obtain the previous serial number.

 If the file does not exist, you know the program has not yet run today
 and you can start the serial number at 1.

 Probably overkill; simpler to have just one file and record the date.
 Just be careful of definitions - do you use the current date UTC or
 the current date local time? And be aware of what might happen if the
 local clock is changed.

 ChrisA

 On Thu, Feb 28, 2013 at 9:41 PM, Morten Engvoldsen mortene...@gmail.com 
 wrote:

 Hi,
 Okey i have wrote the below program as you suggested:

 import time
 from datetime import date

 def salesrecord():
 serial_number = 0
 sales_recrod = {'record1':'product1', 
 'record2':'product2','record3':'product3'}
 for i in sales_recrod:
 print sales_recrod[i]

 serial_number += 1
 print serial_number
 fo = open(workfile.txt, wb)
 fo.write(str(serial_number))
 fo.close()
 with open(workfile.txt, 'r') as f:
 serial_number = f.read()
 today = date.today()



 salesrecord()


 Here i am bit confuse with where i should write the read file function to 
 read the current serial number and date. also when i overwrite the file with 
 current serial number, it will overwrite the date also with current date, in 
 that case how will i  compare the date. Can you please show me in my example 
 how can i achive this..


 -- Forwarded message --
 From: Matt Jones matt.walker.jo...@gmail.com
 To: python-list@python.org python-list@python.org
 Cc:
 Date: Thu, 28 Feb 2013 13:11:38 -0600
 Subject: Re: Issue with continous incrementing of unbroken sequence for a 
 entire working day
 Store the day as well as the serial_number in your file.  If the day is the 
 same as today's day, use the serial_number, if not, use 1.  At the end of 
 you program write the current day and serial_number.

 Matt Jones


 On Thu, Feb 28, 2013 at 1:00 PM, Morten Engvoldsen mortene...@gmail.com 
 wrote:
 Hi,
 thanks for youe suggestion. I think i will go for your second option:

 # Runs this loop until killed
 while True
 do some stuff: clean serial_number, if day changed, calculate salesrecord 
 etc.

 serial_number = salesrecord(serial_number)


 But, if i save the serial_ number value in file, then how  will it decide to 
 reset the serial number to '1' when the batch  runs on next working day. 
 What condition can be good, so that next day when the batch runs, it will 
 know it has to reset the value 1.  Also my batch will not automatcilly run 
 whole day, this is user's decision how many times he wants to run the batch 
 in a day. Can you elebrate more how can i do that ...

 -- Forwarded message --
 From: Morten Engvoldsen mortene...@gmail.com
 Date: Thu, Feb 28, 2013 at 5:31 PM
 Subject: Issue with continous incrementing of unbroken sequence for a entire 
 working day
 To: python-list@python.org


 Hi team,
 I need to run a batch of sales records and  the batch has serial_number 
 filed to store the serial number of the sales record. The serial number 
 should be set to  1 everyday when the batch runs first time in a day and the 
 maximum serial number could be 1000.

 So when the batch runs first time in a day and if it has 10 records, so the 
 last serial number will be 10. And when the batch runs 2nd time in same day, 
 the serial number should start from 11.  In this way serial_number will 
 increment as an unbroken series throughout the entire working day. The next 
 day when the batch runs first time the serial number will reset to 1.

 Now this could be sample code how the program can count the sequence 

Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread Terry Reedy
The subject line is wrong. There are multiple compilers. Someone just 
listed some of them today in another post.


On 2/28/2013 3:50 PM, Matty Sarro wrote:

Python is an interpreted language, not a compiled language.


A language is just a language. Implementations are implementations*. 
That aside, I pretty much agree with the rest of the response.


* For instance, C is usually compiled, but I once used a C interpreter 
on unix.


--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list



Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread Nobody
On Thu, 28 Feb 2013 12:25:07 -0800, kramer65 wrote:

 I'm using Python for a while now and I love it. There is just one thing
 I cannot understand. There are compilers for languages like C and C++.
 why is it impossible to create a compiler that can compile Python code
 to machinecode?

It's not impossible, it's just pointless.

Because Python is dynamically-typed and late-bound, practically nothing is
fixed at compile time. So a compiled Python program would just be a
sequence of calls to interpreter functions.

 Where is my reasoning wrong here? Is that because Python is dynamically
 typed? Does machinecode always need to know whether a variable is an int
 or a float?

Yes.

 And if so, can't you build a compiler which creates
 machinecode that can handle both ints and floats in case of doubt?

Yes. But it's not just ints and floats. E.g. Python's + operator works
on any pair of objects provided that either the left-hand operand has an
__add__ method or the right-hand operand has a __radd__ method.

 Or is it actually possible to do, but so much work that nobody does it?

It's not that it's so much work as much as the fact that the resulting
executable wouldn't be any faster than using the interpreter. IOW, it's so
much work for little or no gain.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read csv file and create a new file

2013-02-28 Thread io

 Just use a tolower() method on both strings when you're comparing them.
   Of course, that may not work well with international character sets.
 Some characters in some languages have no lowercase equivalent, and
 using toupper() has the same problem in other languages.
 
 Also, the approach to case insensitive differs between Python 2.x and
 3.x

Thanks for the info !
What about str().lower()?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Largest possible size for executemany() in PEP-249 (Database API)

2013-02-28 Thread Neil Hodgson

Roy Smith:


_mysql_exceptions.OperationalError: (1153, Got a packet bigger than
'max_allowed_packet' bytes)

Is there any way (other than trial and error) to know how many records
I can pass in one call before I blow up?


   Its unlikely to be a limit in the number of records but a limit on 
the number of bytes in the serialized command stream. With a deep 
understanding of the format you could count bytes until about to go over 
and then flush. I'd *guess* that the data is being sent as textual SQL 
INSERT statements so you could work out what your insertions look like 
as INSERT statements and see how many fit into max_allowed_packet. 
max_allowed_packet is probably 1 million so looking like 100 bytes per 
INSERT but will depend on data as inserting Ko should use less bytes 
than inserting Naragarajan.


   Neil
--
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions for improving code fragment please

2013-02-28 Thread Tim Chase
On 2013-02-28 16:28, Dave Angel wrote:
 On 02/28/2013 03:37 PM, Tim Chase wrote:
 for attr in (myparm1, myparm2, myparm3, ...):
   if arglist:
 setattr(self, attr, arglist.pop(0))
   else:
 break
 
 Or something like (untested):
 
  for name, value in zip([myparm1, myparm2, myparm3],
 arglist): setattr(self, name, value)
  arglist = [] #if you care how it ends up

The OP's code modified arglist by .pop(0) so I maintained the same
behavior.  This is useful if additional arguments beyond the N named
ones are used for some other purpose and you don't want to figure out
how many were taken. Otherwise, if one wants to keep arglist, Dave's
zip() solution is a cleaner way to go.

-tkc


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raw format string in string format method?

2013-02-28 Thread Rick Johnson
On Thursday, February 28, 2013 8:11:17 AM UTC-6, Helmut Jarausch wrote:
 Hi,
 
 
 
 I'd like to print a string with the string format method which uses
 {0}, ...

/What/ uses {0} exactly? The substring you wish to inject or the format 
method? If the latter, we are aware of that!

 Unfortunately, the string contains TeX commands which use lots of
 braces. Therefore I would have to double all these braces just for the
 format method which makes the string hardly readable.

 {0} balls.format(howdy{0} {doody}{10} had {wooden})
'howdy{0} {doody}{10} had {wooden} balls'

But then why even bother to use the format method? Seriously, if you expect 
people to give a proper answer you need to not only explain the problem, but 
also, supply a simplified code example.

 Is there anything like a raw format string and any other means
 to circumvent this?

Even if there is, why would someone offer advice from such ambiguous input? 
Just because a raw format exists does not mean that /every/ poorly described 
problem will be solved using it.

Please provide adequate info.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions for improving code fragment please

2013-02-28 Thread The Night Tripper
Hi All
thanks very much for the various suggestions - very helpful.

I think I like one of the 'just catch the exception' approaches,
or using Mitya's helper function, which I was clutching towards myself.

Either way, lots of food for thought. This forum really is one of the best 
places around...

Cheers
Jon N
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raw format string in string format method?

2013-02-28 Thread Rick Johnson
On Thursday, February 28, 2013 8:42:31 AM UTC-6, Helmut Jarausch wrote:

 Originally I had used percent-formatting
 But isn't  it deprecated in Python 3.X ?

I don't know the current state of percent formats future, however, i can tell 
you that it should be deprecated ASAP!

Simpleminded Sam blubbered:  But rick, how will we format strings that 
contain curly braces without the percent format option? We can't live without 
percent formatting, we are but simple minded folks! *sky-falling* 

Easy Sam. You allow the user to pass opener and closer chars to the format 
function.

 Elvis {has} 0 the {{{ building.format('left', opener='', closer='')
'Elvis {has} left the {{{ building'

For strings that contain all braces you could even create something unique:

 (Elvis) {has} {S}0{E} the building.format('left', opener='{S}', 
 closer='{E}')
'(Elvis) {has} left the building'
-- 
http://mail.python.org/mailman/listinfo/python-list


HTC ChaCha review

2013-02-28 Thread 23alagmy
HTC ChaCha review

http://natigtas7ab.blogspot.com/2012/10/htc-chacha-review.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raw format string in string format method?

2013-02-28 Thread Mark Lawrence

On 28/02/2013 14:42, Helmut Jarausch wrote:

On Fri, 01 Mar 2013 01:22:48 +1100, Chris Angelico wrote:


On Fri, Mar 1, 2013 at 1:11 AM, Helmut Jarausch jarau...@skynet.be
wrote:

Hi,

I'd like to print a string with the string format method which uses
{0}, ...

Unfortunately, the string contains TeX commands which use lots of
braces. Therefore I would have to double all these braces just for the
format method which makes the string hardly readable.

Is there anything like a raw format string and any other means to
circumvent this?


You could use a different string formatting function, such as
percent-formatting:

Hello, {0}, this is %s % some_string

The {0} will be output literally, and the %s will be replaced by the
string. Braces are ignored, percent signs are significant.

ChrisA


Originally I had used percent-formatting
But isn't  it deprecated in Python 3.X ?

Thanks,
Helmut.



Nope please see 
http://mail.python.org/pipermail/python-dev/2012-February/116790.html


--
Cheers.

Mark Lawrence

--
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-28 Thread alex23
On Mar 1, 4:28 am, Rick Johnson rantingrickjohn...@gmail.com wrote:
 And by the way Alex, you are free to put *your* face into the conversation 
 anytime you like.

You're such a little fascist.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read csv file and create a new file

2013-02-28 Thread Dave Angel

On 02/28/2013 05:05 PM, io wrote:



Just use a tolower() method on both strings when you're comparing them.
   Of course, that may not work well with international character sets.
Some characters in some languages have no lowercase equivalent, and
using toupper() has the same problem in other languages.

Also, the approach to case insensitive differs between Python 2.x and
3.x


Thanks for the info !
What about str().lower()?



Actually, it's str.lower(), and that's what I meant.  Must be some other 
language that uses tolower().


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Twisted or Tornado?

2013-02-28 Thread Jake Angulo
I have to say it first: I am not trolling :P

Im working on a server project (with IOS client) and would like to create a 
custom, lean and mean server - real Quick!

My requirements for this framework in descending order:
1) Easy to use API
2) Widely available documentation / Examples / Community contributions
3) Feature-wise - kinda most that you commonly need is there

Your opinions will be valuable, if possible cite examples or URL references, 
Pls!  

I prefer opinion from those who have programmed real projects in it - not just 
read some blog or Slashdot :P
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Twisted or Tornado?

2013-02-28 Thread Michael Torrie
On 02/28/2013 05:28 PM, Jake Angulo wrote:
 My requirements for this framework in descending order: 1) Easy to
 use API 2) Widely available documentation / Examples / Community
 contributions 3) Feature-wise - kinda most that you commonly need is
 there

By this I take it you mean you want to export a standard web services
API, right (RPC over HTTP)?  Or are you insisting on writing your own
protocol?

If it's the first, I recommend something like web2py.
http://web2py.com/books/default/chapter/29/10.  Or Django.  Sounds heavy
but it's really not that bad especially if you don't need a real web UI,
but are just exposing an RPC api.

If it's the second, then, well, yes Twisted will work great, provided
you can understand how it works. It's actually not that complicated, but
python's dynamic nature can sometimes hide how things work from you at
first and what exactly is getting passed around from function to
function.  Took me about a month to really grok Twisted.  Now that my
project is done (quite successful actually... a full-blow LDAP proxy
server), I have forgotten much about how Twisted works.

In another vein, there's node.js as well.  Apparently it's being used a
lot to implement quick and dirty services like what you need.

 I prefer opinion from those who have programmed real projects in it -
 not just read some blog or Slashdot :P

Ha.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speeding up Python's exit

2013-02-28 Thread Grant Edwards
On 2013-02-28, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:

 I know there is a function os._exit which effectively kills the
 Python interpreter dead immediately, without doing any cleanup. What
 are the consequences of doing this?

You loose any data you haven't saved to disk.

 I assume that the memory used by the Python process will be reclaimed
 by the operating system, but other resources such as opened files may
 not be.

All open files (including sockets, pipes, serial ports, etc) will be
flushed (from an OS standpoint) and closed.  If you've closed all the
files you've written to, there should be no danger in just pulling the
plug.

-- 
Grant

-- 
http://mail.python.org/mailman/listinfo/python-list


QT Inspired web development framework for python

2013-02-28 Thread timothy crosley
Hi Everyone,

I've been working on a web development framework that integrates several 
popular QT features (such as a graphical template builder, signal / slots, ui's 
built by objects) for the last few years, and I was hoping that some people 
here might find it useful.

If you are interested the main link for the widgets is http://www.webelements.in
and the link for the framework overall is http://www.webbot.ws

Thanks!

Timothy
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: dbf (aka Python dBase)

2013-02-28 Thread Ethan Furman

The latest version, 0.95.001, is available on PyPI:

http://python.org/pypi/dbf


dbf v0.95.001
=

dbf (also known as python dbase) is a module for reading/writing
dBase III, FP, VFP, and Clipper .dbf database files.  It's
an ancient format that still finds lots of use (the most common
I'm aware of is retrieving legacy data so it can be stored in a
newer database system; other uses include GIS, stand-alone programs
such as Family History, Personal Finance, etc.).

Highlights
--

Table -- represents a single .dbf/.dbt (or .fpt) file combination
and provides access to records; suports the sequence access and 'with'
protocols.  Temporary tables can also live entirely in memory.

Record -- repesents a single record/row in the table, with field access
returning native or custom data types; supports the sequence, mapping,
attribute access (with the field names as the attributes), and 'with'
protocols.  Updates to a record object are reflected on disk either
immediately (using gather() or write()), or at the end of a 'with'
statement.

Index -- nonpersistent index for a table.

Fields:
dBase III (Null not supported)

Character -- unicode
Date  -- datetime.date or None
Logical   -- bool or None
Memo  -- unicode or None
Numeric   -- int/float depending on field definition or None

Float -- same as numeric

Clipper (Null not supported)

Character -- unicode  (character fields can be up to 65,519)

Foxpro (Null supported)

General   -- str (treated as binary)
Picture   -- str (treated as binary)

Visual Foxpro (Null supported)

Currency  -- decimal.Decimal
douBle-- float
Integer   -- int
dateTime  -- datetime.datetime

If a field is uninitialized (Date, Logical, Numeric, Memo, General,
Picture) then None is returned for the value.

Custom data types:

Null --  used to support Null values

Char --  unicode type that auto-trims trailing whitespace, and
  ignores trailing whitespace for comparisons

Date --  date object that allows for no date

DateTime --  datetime object that allows for no datetime

Time --  time object that allows for no time

Logical  --  adds Unknown state to bool's: instead of True/False/None,
  values are Truth, Falsth, and Unknown, with appropriate
  tri-state logic with one caveat: as a matter of practicality
  bool(Falsth) and bool(Unknown) are both False; if you want
  bool(Unknown) to raise a TypeError instead, use Quantums.
  __index__ of Unknown is 2, Truth is 1, and Falsth is 0.

Quantum  --  similar to Logical, but implements boolean algebra (I think)


Whirlwind Tour
--

import datetime
import dbf

table = dbf.Table(':test:', 'name C(25); age N(3,0); birth D; qualified L')
table.open()

for datum in (
('Spanky', 7, dbf.Date.fromymd('20010315'), False),
('Spunky', 23, dbf.Date(1989, 07, 23), True),
('Sparky', 99, dbf.Date(), dbf.Unknown),
):
table.append(datum)

for record in table:
print record
print ''
print record[0:3]
print record['name':'birth']
print [record.name, record.age, record.birth]
print ''

custom = table.new(
filename='test_on_disk',
default_data_types=dict(C=dbf.Char, D=dbf.Date, L=dbf.Logical),
)

with custom:# automatically opened and closed
for record in table:
custom.append(record)
for record in custom:
dbf.write(record, name=record.name.upper())
print record
print ''
print record[0:3]
print record['name':'birth']
print [record.name, record.age, record.birth]
print ''

table.close()
--
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions for improving code fragment please

2013-02-28 Thread Steven D'Aprano
On Thu, 28 Feb 2013 19:47:12 +, The Night Tripper wrote:

 Hi there
 I'm being very dumb ... how can I simplify this fragment?

I suggest that the best way to simplify that fragment is to change the 
design of your class so it isn't so horrible. As it stands now, your 
class defines an arbitrary number of params, which *may or may not exist*:

 if arglist:
 arglist.pop(0)
 if arglist:
 self.myparm1 = arglist.pop(0)
 if arglist:
 self.myparm2 = arglist.pop(0)
 if arglist:
 self.myparm3 = arglist.pop(0)
 if arglist:
 self.parm4 = arglist.pop(0)
 # ...

So using your class is a horrible experience:

if hasattr(instance, 'param1'):
do_something_with(instance.param1)
else:
fall_back_when_param1_doesnt_exist()
if hasattr(instance, 'param2'):
do_something_with(instance.param2)
else:
fall_back_when_param2_doesnt_exist()
if hasattr(instance, 'param3'):
print Do you hate this class yet?



We have a perfectly good programming idiom to deal with a variable number 
of values: the list, or tuple if you prefer. So here's an alternative:

self.params = arglist[1:]

If order is not important:

self.params = set(arglist[1:])


If you have to map names to values:

self.params = dict(
('param%d' % i, value) for i, value in enumerate(arglist[1:])
)


If you absolutely must have named attributes, I recommend that you choose 
a default value that indicates missing. Conventionally, that is None, 
but you can always create your own sentinel value if needed:

SENTINEL = object()
arglist = arglist + [SENTINEL]*20
for i in range(1, 21):
setattr(self, 'param%d' % i, arglist[i])



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread Steven D'Aprano
On Thu, 28 Feb 2013 15:50:00 -0500, Matty Sarro wrote:

 Python is an interpreted language, not a compiled language.

Actually, *languages* are neither interpreted nor compiled. A language is 
an abstract description of behaviour and syntax. Whether something is 
interpreted or compiled or a mixture of both is a matter of the 
implementation. There are C interpreters and Python compilers.



[...]
 Now, there are places where this line is blurred. For instance perl is
 an interpreted language, but capable of running EXTREMELY fast. Python
 is a little slower, but significantly easier to read and write than
 perl. You also have some weird ones like JAVA which actually have a
 virtual machine, and half compile source code into java bytecode.
 This is then executed by the virtual machine.

Welcome to the 20th century -- nearly all so-called interpreted 
languages do that, including Python. Why do you think Python has a 
function called compile, and what do you think the c in .pyc files 
stands for?

The old model that you might have learned in school:

* interpreters read a line of source code, execute it, then read the next 
line, execute it, then read the next one, and so forth...

* compilers convert the entire source code to machine code, then execute 
the machine code.


hasn't been generally true since, well, probably forever, but certainly 
not since the 1980s.

These days, the best definition of interpreted language that I have 
read comes from Roberto Ierusalimschy, one of the creators of Lua:

...the distinguishing feature of interpreted languages is not that they 
are not compiled, but that the compiler is part of the language runtime 
and that, therefore, it is possible (and easy) to execute code generated 
on the fly.

(Programming in Lua, 2nd edition, page 63.)

In that sense, being an interpreter is a feature, and pure compilers are 
deficient.


Oh, by the way, while it is true that the original version of Java used a 
pure virtual machine model, these days many Java compilers are capable of 
producing machine code.

Just to drive home the lesson that *languages* aren't compiled or 
interpreted, but *implementations* are, consider these Python 
implementations with radically different execution styles:

1) CPython, the one you are used to, compiles code to byte-code for a 
custom-made virtual machine;

2) Jython generates code to run on a Java virtual machine;

3) IronPython does the same for the .Net CLR;

4) PyPy has a JIT compiler that generates machine code at runtime;

5) Pynie compiles to byte-code for the Parrot virtual machine;

6) Nuitka includes a static compiler that compiles to machine code;

7) Berp generates Haskell code, which is then compiled and executed by a 
Haskell compiler, which may or may not generate machine code;

8) Pyjamas compiles Python to Javascript;

and others.


And even machine code is not actually machine code. Some CPUs have an 
even lower level of micro-instructions, and an interpreter to translate 
the so-called machine code into micro-instructions before executing 
them.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Store a variable permanently

2013-02-28 Thread eli m
So i have a variable called funds that i want to store the value of even after 
the program is exited. My funds variable holds the total value of funds i have. 
I add a certain number of funds each time i run the program by entering how 
much i want to add. How would i store the funds variable to keep its value?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Store a variable permanently

2013-02-28 Thread Steven D'Aprano
On Thu, 28 Feb 2013 19:35:57 -0800, eli m wrote:

 So i have a variable called funds that i want to store the value of even
 after the program is exited. My funds variable holds the total value of
 funds i have. I add a certain number of funds each time i run the
 program by entering how much i want to add. How would i store the funds
 variable to keep its value?

You have to write it to a file, then read it back in when the program 
starts.

Do you need help with reading and writing files?

Perhaps the easiest way to do this is with the configparser or plistlib 
modules.

http://docs.python.org/2/library/configparser.html
http://docs.python.org/2/library/plistlib.html


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread Steven D'Aprano
On Thu, 28 Feb 2013 22:03:09 +0100, Stefan Behnel wrote:

 The most widely used static Python compiler is Cython

Cython is not a Python compiler. Cython code will not run in a vanilla 
Python implementation. It has different keywords and syntax, e.g.:

cdef inline int func(double num):
...


which gives SyntaxError in a Python compiler.

Cython is an excellent language and a great addition to the Python 
ecosystem, but it is incorrect to call it Python.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Store a variable permanently

2013-02-28 Thread Mitya Sirenef

On 02/28/2013 10:35 PM, eli m wrote:
So i have a variable called  funds that i want to store the value of even after the program is 
exited. My funds variable holds the total value of funds i have. I add a 
certain number of funds each time i run the program by entering how much 
i want to add. How would i store the funds variable to keep its value?



Take a look at these examples from shelve module doc page:

http://docs.python.org/2/library/shelve.html#example

-m


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

Fashion is something barbarous, for it produces innovation without reason
and imitation without benefit.  George Santayana

--
http://mail.python.org/mailman/listinfo/python-list


Re: raw format string in string format method?

2013-02-28 Thread Chris Angelico
On Fri, Mar 1, 2013 at 10:27 AM, Rick Johnson
rantingrickjohn...@gmail.com wrote:
 On Thursday, February 28, 2013 8:42:31 AM UTC-6, Helmut Jarausch wrote:

 Originally I had used percent-formatting
 But isn't  it deprecated in Python 3.X ?

 I don't know the current state of percent formats future, however, i can 
 tell you that it should be deprecated ASAP!

On Fri, Mar 1, 2013 at 11:00 AM, Mark Lawrence breamore...@yahoo.co.uk wrote:
 Nope please see
 http://mail.python.org/pipermail/python-dev/2012-February/116790.html

And there, folks, you have it. The known troll demands its removal, a
core dev says that it's staying.

Percent formatting is a viable parallel to .format(), with some handy
differences - such as the distinction of significant characters, as
proven here.

Both are going to stay, and I'm glad of it!

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread Steven D'Aprano
On Thu, 28 Feb 2013 12:25:07 -0800, kramer65 wrote:

 Hello,
 
 I'm using Python for a while now and I love it. There is just one thing
 I cannot understand. There are compilers for languages like C and C++.
 why is it impossible to create a compiler that can compile Python code
 to machinecode?

Your assumption is incorrect. You can compile Python to machine-code, at 
least sometimes. It is quite tricky, for various reasons, but it can be 
done, at various levels of efficiency.

One of the oldest such projects was Psyco, which was a Just-In-Time 
compiler for Python. When Psyco was running, it would detect at run time 
that you were doing calculations on (say) standard ints, compile on the 
fly a machine-code function to perform those calculations, and execute 
it. Psyco has more or less been made obsolete by PyPy, which does the 
same thing only even more so.

http://en.wikipedia.org/wiki/Psyco
http://en.wikipedia.org/wiki/PyPy


 My reasoning is as follows:
 When GCC compiles a program written in C++, it simply takes that code
 and decides what instructions that would mean for the computer's
 hardware. What does the CPU need to do, what does the memory need to
 remember, etc. etc. If you can create this machinecode from C++, then I
 would suspect that it should also be possible to do this (without a
 C-step in between) for programs written in Python.

In principle, yes, but in practice it's quite hard, simply because Python 
does so much more at runtime than C++ (in general).

Take an expression like:

x = a + b

In C++, the compiler knows what kind of data a and b are, what kind of 
data x is supposed to be. They are often low-level machine types like 
int32 or similar, which the CPU can add directly (or at least, the 
compiler can fake it). Even if the variables are high-level objects, the 
compiler can usually make many safe assumptions about what methods will 
be called, and can compile instructions something like this pseudo-code:

10 get the int64 at location 12348   # a
20 get the int64 at location 13872   # b
30 jump to the function at location 93788  # add two int64s
40 store the result at location 59332  # x

which is fast and efficient because most of the hard work is done at 
compile time. But it's also quite restrictive, because you can't change
code on the fly, create new types or functions, etc. (Or, where you can,
then you lose some of the advantages of C++ and end up with something
like Python but with worse syntax.)

In Python, you don't know what a and b are until runtime. They could be 
ints, or lists, or strings, or anything. The + operator could call a 
custom __add__ method, or a __radd__ method, from some arbitrary class. 
Because nearly everything is dynamic, the Python compiler cannot safely 
make many assumptions about the code at compile time. So you end up with 
code like this:

10 search for the name a and take note of it
20 search for the name b and take note of it
30 decide whether to call a.__add__ or b.__radd__
40 call the appropriate method
60 bind the result to the name x


You can get an idea of what Python actually does by disassembling the 
byte code into pseudo-assembly language:


py code = compile(x = a + b, '', 'single')
py from dis import dis
py dis(code)
  1   0 LOAD_NAME0 (a) 
  3 LOAD_NAME1 (b) 
  6 BINARY_ADD   
  7 STORE_NAME   2 (x) 
 10 LOAD_CONST   0 (None) 
 13 RETURN_VALUE 


Nevertheless, PyPy can often speed up Python code significantly, 
sometimes to the speed of C or even faster.

http://morepypy.blogspot.com.au/2011/02/pypy-faster-than-c-on-carefully-crafted.html

http://morepypy.blogspot.com.au/2011/08/pypy-is-faster-than-c-again-string.html



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread alex23
On Mar 1, 1:47 pm, Steven D'Aprano steve
+comp.lang.pyt...@pearwood.info wrote:
 Cython is not a Python compiler. Cython code will not run in a vanilla
 Python implementation. It has different keywords and syntax, e.g.:

 cdef inline int func(double num):
     ...

 which gives SyntaxError in a Python compiler.

Cython has had a pure Python mode for several years now that allows
you to decorate Python code or augment it with additional files
containing the C specific declarations:

http://docs.cython.org/src/tutorial/pure.html

Both of which will be ignored by the regular Python interpreter,
allowing you to write Python that is also suitable for Cython without
the errors you mention.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread alex23
On Mar 1, 6:25 am, kramer65 kram...@gmail.com wrote:
 There are compilers for languages like C and C++. why
 is it impossible to create a compiler that can compile
 Python code to machinecode?

This is a nice site list a lot of current approaches to that subject:

http://compilers.pydata.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: QT Inspired web development framework for python

2013-02-28 Thread Michael Torrie
On 02/28/2013 06:48 PM, timothy crosley wrote:
 I've been working on a web development framework that integrates several 
 popular QT features (such as a graphical template builder, signal / slots, 
 ui's built by objects) for the last few years, and I was hoping that some 
 people here might find it useful.
 
 If you are interested the main link for the widgets is 
 http://www.webelements.in
 and the link for the framework overall is http://www.webbot.ws

Very professional-looking pages, I must say!

How would your framework fit into a framework such as Django? In other
words, could it be used as the view part of django?  Or is it meant to
completely replace a traditional web framework?
-- 
http://mail.python.org/mailman/listinfo/python-list


Having problems crashing IDLE

2013-02-28 Thread Quintessence
I've been learning Python over the past week or so and I keep running into an 
issue where opening saved files will crash IDLE (not consistently, sometimes 
the same files with no changes will open and sometimes not). I was originally 
running Python 3.2.3, but I removed it and upgraded to 3.3.0 hoping to resolve 
the issue (but to no avail). While troubleshooting, someone suggested I try 
opening IDLE via command prompt. When I do that IDLE never crashes, but It does 
show this error (screenshot):
http://i.imgur.com/1JqiRsY.png (3.2.3)
http://i.imgur.com/5KxE88K.png (3.3.0)


Some additional info:
- When IDLE crashes it does not display an error, every open window simply 
closes.
- IDLE has never crashed after opening a file when I open it via command 
prompt, even if it was previously consistently displaying that behavior.
- I am running Windows 7 x64 with all updates.

Has anyone ever encountered this? What does the error mean?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

2013-02-28 Thread 88888 Dihedral
kramer65於 2013年3月1日星期五UTC+8上午4時25分07秒寫道:
 Hello,
 
 
 
 I'm using Python for a while now and I love it. There is just one thing I 
 cannot understand. There are compilers for languages like C and C++. why is 
 it impossible to create a compiler that can compile Python code to 
 machinecode?
 
 
 
 My reasoning is as follows:
 
 When GCC compiles a program written in C++, it simply takes that code and 
 decides what instructions that would mean for the computer's hardware. What 
 does the CPU need to do, what does the memory need to remember, etc. etc. If 
 you can create this machinecode from C++, then I would suspect that it should 
 also be possible to do this (without a C-step in between) for programs 
 written in Python.
 
 
 
 Where is my reasoning wrong here? Is that because Python is dynamically 
 typed? Does machinecode always need to know whether a variable is an int or a 
 float? And if so, can't you build a compiler which creates machinecode that 
 can handle both ints and floats in case of doubt? Or is it actually possible 
 to do, but so much work that nobody does it?
 
 
 
 I googled around, and I *think* it is because of the dynamic typing, but I 
 really don't understand why this would be an issue..
 
 
 
 Any insights on this would be highly appreciated!

I think a smart object can perform some experiments in its lifetime
in sensing and collecting data to improve its methods in the long run.

This will require a dynamical language definitely.

-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >