Re: Py3.3 unicode literal and input()
On Jun 20, 1:21 am, Steven D'Aprano wrote: > On Mon, 18 Jun 2012 07:00:01 -0700, jmfauth wrote: > > On 18 juin, 12:11, Steven D'Aprano > [email protected]> wrote: > >> On Mon, 18 Jun 2012 02:30:50 -0700, jmfauth wrote: > >> > On 18 juin, 10:28, Benjamin Kaplan wrote: > >> >> The u prefix is only there to > >> >> make it easier to port a codebase from Python 2 to Python 3. It > >> >> doesn't actually do anything. > > >> > It does. I shew it! > > >> Incorrect. You are assuming that Python 3 input eval's the input like > >> Python 2 does. That is wrong. All you show is that the one-character > >> string "a" is not equal to the four-character string "u'a'", which is > >> hardly a surprise. You wouldn't expect the string "3" to equal the > >> string "int('3')" would you? > > >> -- > >> Steven > > > A string is a string, a "piece of text", period. > > > I do not see why a unicode literal and an (well, I do not know how the > > call it) a "normal class " should behave differently in code source > > or as an answer to an input(). > > They do not. As you showed earlier, in Python 3.3 the literal strings > u'a' and 'a' have the same meaning: both create a one-character string > containing the Unicode letter LOWERCASE-A. > > Note carefully that the quotation marks are not part of the string. They > are delimiters. Python 3.3 allows you to create a string by using > delimiters: > > ' ' > " " > u' ' > u" " > > plus triple-quoted versions of the same. The delimiter is not part of the > string. They are only there to mark the start and end of the string in > source code so that Python can tell the difference between the string "a" > and the variable named "a". > > Note carefully that quotation marks can exist inside strings: > > my_string = "This string has 'quotation marks'." > > The " at the start and end of the string literal are delimiters, not part > of the string, but the internal ' characters *are* part of the string. > > When you read data from a file, or from the keyboard using input(), > Python takes the data and returns a string. You don't need to enter > delimiters, because there is no confusion between a string (all data you > read) and other programming tokens. > > For example: > > py> s = input("Enter a string: ") > Enter a string: 42 > py> print(s, type(s)) > 42 > > Because what I type is automatically a string, I don't need to enclose it > in quotation marks to distinguish it from the integer 42. > > py> s = input("Enter a string: ") > Enter a string: This string has 'quotation marks'. > py> print(s, type(s)) > This string has 'quotation marks'. > > What you type is exactly what you get, no more, no less. > > If you type 42, you get the two character string "42" and not the int 42. > > If you type [1, 2, 3], then you get the nine character string "[1, 2, 3]" > and not a list containing integers 1, 2 and 3. > > If you type 3**0.5 then you get the six character string "3**0.5" and not > the float 1.7320508075688772. > > If you type u'a' then you get the four character string "u'a'" and not > the single character 'a'. > > There is nothing new going on here. The behaviour of input() in Python 3, > and raw_input() in Python 2, has not changed. > > > Should a user write two derived functions? > > > input_for_entering_text() > > and > > input_if_you_are_entering_a_text_as_litteral() > > If you, the programmer, want to force the user to write input in Python > syntax, then yes, you have to write a function to do so. input() is very > simple: it just reads strings exactly as typed. It is up to you to > process those strings however you wish. > > -- > Steven Python 3.3.0a4 (v3.3.0a4:7c51388a3aa7+, May 31 2012, 20:15:21) [MSC v. 1600 32 bit (Intel)] on win32 >>> --- running smidzero.py... ...smidzero has been executed >>> --- input(':') :éléphant 'éléphant' >>> --- input(':') :u'éléphant' 'éléphant' >>> --- input(':') :u'\u00e9l\xe9phant' 'éléphant' >>> --- input(':') :u'\U00e9léphant' 'éléphant' >>> --- input(':') :\U00e9léphant 'éléphant' >>> --- >>> --- # this is expected >>> --- input(':') :b'éléphant' "b'éléphant'" >>> --- len(input(':')) :b'éléphant' 11 --- Good news on the ru''/ur'' front: http://bugs.python.org/issue15096 --- Finally I'm just wondering if this unicode_literal reintroduction is not a bad idea. b'these_are_bytes' u'this_is_a_unicode_string' I wrote all my Py2 code in a "unicode mode" since ... Py2.3 (?). jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: Py3.3 unicode literal and input()
Am 18.06.2012 20:45, schrieb Terry Reedy: > The simultaneous reintroduction of 'ur', but with a different meaning > than in 2.7, *was* a problem and it should be removed in the next release. FYI: http://hg.python.org/cpython/rev/8e47e9af826e Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Py3.3 unicode literal and input()
On Jun 20, 11:22 am, Christian Heimes wrote: > Am 18.06.2012 20:45, schrieb Terry Reedy: > > > The simultaneous reintroduction of 'ur', but with a different meaning > > than in 2.7, *was* a problem and it should be removed in the next release. > > FYI:http://hg.python.org/cpython/rev/8e47e9af826e > > Christian I saw this, not the latest version. Anyway, thanks for the info. jmf -- http://mail.python.org/mailman/listinfo/python-list
ANN: Python Meeting Düsseldorf - 17.07.2012
[This announcement is in German since it targets a local user group meeting in Düsseldorf, Germany] ANKÜNDIGUNG Python Meeting Düsseldorf http://pyddf.de/ Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosphäre. Dienstag, 17.07.2012, 18:00 Uhr Clara Schumann Raum DJH Düsseldorf Diese Nachricht können Sie auch online lesen: http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2012-07-17 EINLEITUNG Das Python Meeting Düsseldorf (http://pyddf.de/) ist eine neue lokale Veranstaltung in Düsseldorf, die sich an Python Begeisterte in der Region wendet. Wir starten bei den Treffen mit einer kurzen Einleitung und gehen dann zu einer Reihe Kurzvorträgen (Lightning Talks) über, bei denen die Anwesenden über neue Projekte, interessante Probleme und sonstige Aktivitäten rund um Python berichten können. Anschließend geht es in eine Gaststätte, um die Gespräche zu vertiefen. Einen guten Überblick über die Vorträge bietet unser YouTube-Kanal, auf dem wir die Vorträge nach den Meetings veröffentlichen: http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, Düsseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ ORT Für das Python Meeting Düsseldorf haben wir den Clara Schumann Raum in der modernen Jugendherberge Düsseldorf angemietet: Jugendherberge Düsseldorf Düsseldorfer Str. 1 40545 Düsseldorf Telefon: +49 211 557310 http://www.duesseldorf.jugendherberge.de Die Jugendherberge verfügt über eine kostenpflichtige Tiefgarage (EUR 2,50 pro Stunde, maximal EUR 10,00). Es ist aber auch möglich per Bus und Bahn anzureisen. Der Raum befindet sich im 1.OG links. PROGRAMM Das Python Meeting Düsseldorf nutzt eine Mischung aus Open Space und Lightning Talks: Die Treffen starten mit einer kurzen Einleitung. Danach geht es weiter mit einer Lightning Talk Session, in der die Anwesenden Kurzvorträge von fünf Minuten halten können. Hieraus ergeben sich dann meisten viele Ansatzpunkte für Diskussionen, die dann den Rest der verfügbaren Zeit in Anspruch nehmen können. Für 19:45 Uhr haben wir in einem nahegelegenen Restaurant Plätze reserviert, damit auch das leibliche Wohl nicht zu kurz kommt. Lightning Talks können vorher angemeldet werden, oder auch spontan während des Treffens eingebracht werden. Ein Beamer mit XGA Auflösung steht zur Verfügung. Folien bitte als PDF auf USB Stick mitbringen. Lightning Talk Anmeldung bitte formlos per EMail an [email protected] KOSTENBETEILIGUNG Das Python Meeting Düsseldorf wird von Python Nutzern für Python Nutzer veranstaltet. Da Tagungsraum, Beamer, Internet und Getränke Kosten produzieren, bitten wir die Teilnehmer um einen Beitrag in Höhe von EUR 10,00 inkl. 19% Mwst. Wir möchten alle Teilnehmer bitten, den Betrag in bar mitzubringen. ANMELDUNG Da wir nur für ca. 20 Personen Sitzplätze haben, möchten wir bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung eingegangen. Es erleichtert uns allerdings die Planung. Meeting Anmeldung bitte formlos per EMail an [email protected] WEITERE INFORMATIONEN Weitere Informationen finden Sie auf der Webseite des Meetings: http://pyddf.de/ Mit freundlichen Grüßen, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jun 20 2012) >>> Python/Zope Consulting and Support ...http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ 2012-07-17: Python Meeting Duesseldorf ... 27 days to go 2012-07-02: EuroPython 2012, Florence, Italy ... 12 days to go ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
re.finditer with lookahead and lookbehind
Hi, i have some trouble to split a pattern like s. Even have this problems with the first and last match. Some greedy problems? Thanks in advance Christian import re s='v1=pattern1&v2=pattern2&v3=pattern3&v4=pattern4&v5=pattern5&x1=patternx' pattern =r'(?=[a-z0-9]+=)(.*?)(?<=&)' regex = re.compile(pattern,re.IGNORECASE) for match in regex.finditer(s): print match.group(1) My intention: pattern1 pattern2 pattern3 pattern4 pattern5 patternx -- http://mail.python.org/mailman/listinfo/python-list
Re: re.finditer with lookahead and lookbehind
On 20/06/2012 14:30, Christian wrote:
Hi,
i have some trouble to split a pattern like s. Even have this
problems with the first and last match. Some greedy problems?
Thanks in advance
Christian
import re
s='v1=pattern1&v2=pattern2&v3=pattern3&v4=pattern4&v5=pattern5&x1=patternx'
pattern =r'(?=[a-z0-9]+=)(.*?)(?<=&)'
regex = re.compile(pattern,re.IGNORECASE)
for match in regex.finditer(s):
print match.group(1)
My intention:
pattern1
pattern2
pattern3
pattern4
pattern5
patternx
You could do it like this:
import re
s =
'v1=pattern1&v2=pattern2&v3=pattern3&v4=pattern4&v5=pattern5&x1=patternx'
pattern = r'=([^&]*)'
regex = re.compile(pattern, re.IGNORECASE)
for match in regex.finditer(s):
print match.group(1)
or avoid regex entirely:
>>> values = [p.partition("=")[2] for p in s.split("&")]
>>> values
['pattern1', 'pattern2', 'pattern3', 'pattern4', 'pattern5', 'patternx']
--
http://mail.python.org/mailman/listinfo/python-list
Re: Is that safe to use ramdom.random() for key to encrypt?
On Thu, Jun 21, 2012 at 1:18 AM, wrote: > On 2012-06-17, Jon Clements wrote: >> I generally find a separate partition with an encrypted file-system >> (which is fairly straight forward on *nix systems or I think there's a >> product out there that works with Windows), is a lot easier and puts the >> load on the filesystem/OS instead of having to be handled in your >> application is a lot simpler. > > That assumes he is doing storage rather than communication. Well, for communication it's even easier. Pick up an SSL or SSH library and channel everything through that! Added bonus of SSL/TLS is that, with many languages/libraries, you can write all your code with a simple unencrypted session and test it with telnet, and then "turn on" encryption without changing any of your code outside of your initialization. Whatever platform you're targeting, there's a better option than writing your own encryption. Guaranteed. Even if it means writing glue code to interface to a C library. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Is that safe to use ramdom.random() for key to encrypt?
On 12-06-20 11:18 AM, [email protected] wrote: On 2012-06-17, Jon Clements wrote: Whatever you do - *do not* attempt to write your own algorithm. very true As "they" say, random number generation is too important to be left to chance. :-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. IM: [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: Is that safe to use ramdom.random() for key to encrypt?
Am 20.06.2012 17:25, schrieb D'Arcy Cain: > As "they" say, random number generation is too important to be left > to chance. :-) Hilarious! You made my day! :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter binding question
On Tue, 2012-06-19 at 19:19 -0700, [email protected] wrote: > On Tuesday, June 19, 2012 10:55:48 AM UTC-5, Frederic Rentsch wrote: > > If I copy your event descriptors into my program, the button-release > > callback still fails. It works in your code, not in mine. Here is what > > my code now looks like. It is somewhat more complicated than yours, > > because I bind Frames holding each a line (line_frame) and each frame > > contains a few Labels side by side. The idea is to achieve a table with > > vertically aligning columns each line of which I can click-select. (Is > > there a better way?) > > > >for line_frame in ...: > > line_frame.bind ('', self.color_selected) > > line_frame.bind ('', self.color_selectable) > > line_frame.bind ('', self.pick_record) > > line_frame.bind ('', self.info_profile) > > line_frame.grid (row = n+1, column = 0) > > for i in self.range_n_fields: > > field = Label (line_frame, width = ..., text = ... > > field.grid (row = 0, column = i, sticky = W) > > ... > > > >def color_selected (self, event): > > print 'hit list.color_selected ()' > > > >def color_selectable (self, event): > > print 'hit list.color_selectable ()' > > > >def pick_record (self, event): # Nver gets called > > print 'hit list.pick_record ()' > > > >def info_profile (self, event):# Never gets called > > print 'hit list.info_profile ()' > > Events only fire for the widget that currently has "focus". Frames, labels, > and other widgets do not receive focus simply by hovering over them. You can > set the focus manually by calling "w.focus_set()" -- where "w" is any Tkinter > widget. I can't be sure because i don't have enough of your code to analyze, > but I think you should bind (either globally or by class type) all "Enter" > events to a callback that sets the focus of the current widget under the > mouse. Experiment with this code and see if it is what you need: > > ## START CODE ## > from __future__ import print_function > import Tkinter as tk > > def cb(event): > print(event.widget.winfo_class()) > event.widget.focus_set() > > root = tk.Tk() > root.geometry('200x200+20+20') > for x in range(10): > w = tk.Frame(root, width=20, height=20,bg='red') > w.grid(row=x, column=0, padx=5, pady=5) > w = tk.Frame(root, width=20, height=20,bg='green', highlightthickness=1) > w.grid(row=x, column=1, padx=5, pady=5) > w = tk.Button(root, text=str(x)) > w.grid(row=x, column=2, padx=5, pady=5) > root.bind_all("", cb) > root.mainloop() > ## END CODE ## > > You will see that the first column of frames are recieving focus but you have > no visual cues of that focus (due to a default setting). In the second column > you get the visual cue since i set "highlightthicness=1". The third column is > a button widget which by default has visual focus cues. > > Is this the problem? Yes, I was unaware of focus control. I understand that it is set either by a left mouse button click or the method focus_set (). > PS: Also check out the "w.bind_class()" method. > > > Incidentally, my source of inspiration for chaining event descriptors > > was the New Mexico Tech Tkinter 8.4 reference, > > That's an excellent reference BTW. Keep it under your pillow. Effbot also has > a great tutorial. Thanks for this additional load af advice. Googling I chanced on an excellent introduction "Thinking in Tkinter" by Stephen Ferg. (http://www.ferg.org/thinking_in_tkinter/all_programs.html). He sets out identifying a common problem with tutorials: The problem is that the authors of the books want to rush into telling me about all of the widgets in the Tkinter toolbox, but never really pause to explain basic concepts. They don't explain how to "think in Tkinter". He then explains seventeen functionalities, one at a time, and illustrates them with a little piece of code ready to run. Working through the examples is a good way to acquire a basic understanding without falling victim to "brain clutter". I shall go through the examples very attentively and go on from there. Thanks again Frederic -- http://mail.python.org/mailman/listinfo/python-list
fastest method
I am looking for the fastest way to parse a log file. currently I have this... Can I speed this up any? The script is written to be a generic log file parser so I can't rely on some predictable pattern. def check_data(data,keywords): #get rid of duplicates unique_list = list(set(data)) string_list=' '.join(unique_list) #print string_list for keyword in keywords: if keyword in string_list: return True I am currently using file seek and maintaining a last byte count file: with open(filename) as f: print "Here is filename:%s" %filename f.seek(0, 2) eof = f.tell() print "Here is eof:%s" %eof if last is not None: print "Here is last:%s" %last # if last is less than current last = int(last) if (eof - last > 0): offset = eof - last offset = offset * -1 print "Here is new offset:%s" %offset f.seek(offset, 2) mylist = f.readlines() else: # if last doesn't exist or is greater than current f.seek(0) bof = f.tell() print "Here is bof:%s" %bof mylist = f.readlines() Thanks, -- David Garvey -- http://mail.python.org/mailman/listinfo/python-list
DirectX Screenshot with python possible?
I'm in need for a function that is able to make a screenshot from a directx full screen. PIL is only able to take a snapshot from the desktop, but not from any directx screen. Has someone a tip for an existing module? -- http://mail.python.org/mailman/listinfo/python-list
Re: fastest method
I see one issue;) # if last doesn't exist or is greater than current This else doesn't catch the last greater than current: This is a little messy. with open(filename) as f: print "Here is filename:%s" %filename f.seek(0, 2) eof = f.tell() print "Here is eof:%s" %eof if last is not None: print "Here is last:%s" %last # if last is less than current last = int(last) if (eof - last > 0): offset = eof - last offset = offset * -1 print "Here is new offset:%s" %offset f.seek(offset, 2) mylist = f.readlines() else: f.seek(0) bof = f.tell() print "Here is bof:%s" %bof mylist = f.readlines() else: f.seek(0) bof = f.tell() print "Here is bof:%s" %bof mylist = f.readlines() On Wed, Jun 20, 2012 at 11:17 AM, [email protected] < [email protected]> wrote: > I am looking for the fastest way to parse a log file. > > > currently I have this... Can I speed this up any? The script is written to > be a generic log file parser so I can't rely on some predictable pattern. > > > def check_data(data,keywords): > #get rid of duplicates > unique_list = list(set(data)) > string_list=' '.join(unique_list) > #print string_list > for keyword in keywords: > if keyword in string_list: > return True > > > I am currently using file seek and maintaining a last byte count file: > > with open(filename) as f: > print "Here is filename:%s" %filename > f.seek(0, 2) > eof = f.tell() > print "Here is eof:%s" %eof > if last is not None: > print "Here is last:%s" %last > # if last is less than current > last = int(last) > if (eof - last > 0): > offset = eof - last > offset = offset * -1 > print "Here is new offset:%s" %offset > f.seek(offset, 2) > mylist = f.readlines() > else: > # if last doesn't exist or is greater than current > f.seek(0) > bof = f.tell() > print "Here is bof:%s" %bof > mylist = f.readlines() > > > > Thanks, > -- > David Garvey > -- David Garvey -- http://mail.python.org/mailman/listinfo/python-list
Re: Is that safe to use ramdom.random() for key to encrypt?
In article , Chris Angelico wrote: > Well, for communication it's even easier. Pick up an SSL or SSH > library and channel everything through that! +1 on this. Actually, plus a whole bunch more than 1. I worked on a project which had rolled their own communication layer (including encryption). The decisions were made (long) before I got there, and may well have made sense at the time, but in the end it was a mess. I can't count how many person-years went into fixing hard-to-replicate bugs, not to mention lots of customer ill will when things broke at their sites The upside is I learned a lot about crypto that I probably would have never learned otherwise. That's cool and fun, but not a good justification for putting it in your product. > Added bonus of SSL/TLS is that, with many languages/libraries, you > can write all your code with a simple unencrypted session and test > it with telnet, and then "turn on" encryption without changing any > of your code outside of your initialization. Yup, this is a big win. There's another consideration. At some point, some large customer (or potential customer) may require that all your crypto be FIPS (or whatever national authority) certified. If you're using some standard crypto library, it's a lot easier to drop in a certified replacement than if you've rolled your own. > Whatever platform you're targeting, there's a better option than > writing your own encryption. Guaranteed. Even if it means writing glue > code to interface to a C library. What he said. -- http://mail.python.org/mailman/listinfo/python-list
Custom build of Python
I had reason to build Python 2.6.8 with Microsoft Visual Studio 2010. I was able to get the pcbuild solution to build, and I have the necessary exes/dlls/pyds in the amd64 build directory. What is not clear to is how to complete the build and make an installation. I could not find any documentation for this. Any help on this matter would be appreciated. Thanks, Tom This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email. For other languages, go to http://www.3ds.com/terms/email-disclaimer -- http://mail.python.org/mailman/listinfo/python-list
Re: Py3.3 unicode literal and input()
On Wed, 20 Jun 2012 01:12:00 -0700, jmfauth wrote:
> Python 3.3.0a4 (v3.3.0a4:7c51388a3aa7+, May 31 2012, 20:15:21) [MSC v.
> 1600
> 32 bit (Intel)] on win32
---
> running smidzero.py...
> ...smidzero has been executed
What is "smidzero.py", and what is it doing?
---
> input(':')
> :éléphant
> 'éléphant'
Why are your input lines preceded by three dashes?
---
> input(':')
> :u'éléphant'
> 'éléphant'
---
> input(':')
> :u'\u00e9l\xe9phant'
> 'éléphant'
I cannot reproduce that behaviour. When I try it, I get the expected
result:
>>> input(': ')
: u'\u00e9l\xe9phant'
"u'\\u00e9l\\xe9phant'"
I expect that the mysterious smidzero.py is monkey-patching the input
builtin to do something silly. If that is the case, you are making a rod
for your own back.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
execnet-1.1: cross-interpreter distributed execution library
execnet-1.1 is a backward compatible beta release of the popular (>53000 pypi downloads of 1.0.9) cross-interpreter execution library. If you are in need of connecting Python2 and Python3 and/or want to throw PyPy in your deployment mix, then you might want to join Quora and many others and try out execnet. execnet provides a share-nothing model with channel-send/receive communication and distributed execution across many Python interpreters across version, platform and network barriers. See below for changes and see here for extensive documentation and tested examples: http://codespeak.net/execnet Particular thanks to Ronny Pfannschmidt for a lot of internal cleanups and to Alex Gaynor for providing feature patches. Have fun, holger 1.1 (compared to 1.0.9) - introduce execnet.dumps/loads providing serialization between python interpreters, see http://codespeak.net/execnet/basics.html#dumps-loads - group.remote_exec now supports kwargs as well - support per channel string coercion configuration, helping with dealing with mixed Python2/Python3 environments. - Popen2IO.read now reads correct amounts of bytes from nonblocking fd's - added a ``dont_write_bytecode`` option to Popen gateways, this sets the ``sys.dont_write_bytecode`` flag on the spawned process, this only works on CPython 2.6 and higher. Thanks to Alex Gaynor. - added a pytest --broken-isp option to skip tests that assume DNS queries for unknown hosts actually are resolved as such (Thanks Alex Gaynor) - fix issue 1 - decouple string coercion of channels and gateway - fix issue #2 - properly reconfigure the channels string coercion for rsync, so it can send from python2 to python3 - refactor socketserver, so it can be directly remote_exec'd for starting a socket gateway on a remote -- http://mail.python.org/mailman/listinfo/python-list
Re: Is that safe to use ramdom.random() for key to encrypt?
[email protected] writes: > On 2012-06-17, Jon Clements wrote: > >> Whatever you do - *do not* attempt to write your own algorithm. > > very true If everyone took that advice then we'd have a problem -- http://mail.python.org/mailman/listinfo/python-list
Re: Custom build of Python
On 6/20/2012 2:24 PM, KACVINSKY Tom wrote: I had reason to build Python 2.6.8 with Microsoft Visual Studio 2010. I was able to get the pcbuild solution to build, and I have the necessary exes/dlls/pyds in the amd64 build directory. What is not clear to is how to complete the build and make an installation. I could not find any documentation for this. If you mean 'make a .msi file', I am not sure that is not officially supported beyond the inclusion of msilib. Any help on this matter would be appreciated. 3.3 is now being built with VS2010. Perhaps its repository has something that will help you. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: DirectX Screenshot with python possible?
On 6/20/2012 2:24 PM, Sverre wrote: I'm in need for a function that is able to make a screenshot from a directx full screen. PIL is only able to take a snapshot from the desktop, but not from any directx screen. Has someone a tip for an existing module? Perhaps pygame has (or wraps) such a function. If not, someone on the pygame list must know how. (I am assuming that sdl library and hence pygame use directx.) -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
RE: Custom build of Python
Terry, At this stage, I don't want or need an MSI. I just want something that will bundle the executables/dynamic load libraries + compiled Python files and stick them into a compliant directory structure. Regards, Tom -Original Message- From: [email protected] [mailto:[email protected]] On Behalf Of Terry Reedy Sent: Wednesday, June 20, 2012 4:13 PM To: [email protected] Subject: Re: Custom build of Python On 6/20/2012 2:24 PM, KACVINSKY Tom wrote: > I had reason to build Python 2.6.8 with Microsoft Visual Studio 2010. > I was able to get the pcbuild solution to build, and I have the > necessary exes/dlls/pyds in the amd64 build directory. What is not > clear to is how to complete the build and make an installation. I > could not find any documentation for this. If you mean 'make a .msi file', I am not sure that is not officially supported beyond the inclusion of msilib. > Any help on this matter would be appreciated. 3.3 is now being built with VS2010. Perhaps its repository has something that will help you. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email. For other languages, go to http://www.3ds.com/terms/email-disclaimer -- http://mail.python.org/mailman/listinfo/python-list
Re: Py3.3 unicode literal and input()
On Jun 18, 2012 8:07 AM, "jmfauth" wrote: > A string is a string, a "piece of text", period. > > I do not see why a unicode literal and an (well, I do not > know how the call it) a "normal class " should behave > differently in code source or as an answer to an input(). Strings are a data type that contains characters. String literals are *not* strings. They are a code syntax that is used to create actual string objects. Remember: strings are data, string literals are code. input() does not accept string literals because it is a runtime feature that reads data, not code. It does not parse unicode literals or bytes literals or "normal" string literals or integer literals or tuple literals or any other kind of literal. All that it reads is plain, uninterpreted string data. If you want to do any processing of that data, you need to specify it yourself. -- http://mail.python.org/mailman/listinfo/python-list
xlrd 0.7.9 released!
Hi All, I'm pleased to announce the release of xlrd 0.7.9: http://pypi.python.org/pypi/xlrd/0.7.9 This release fixes an annoying merge bug on my part that resulted in a "NameError: global name 'BYTES_X00' is not defined" error where opening certain Excel files. Barring any more brown bag issues, this will be the last release in the 0.7 series and the last release supporting Python 2.1 and 2.2. The next release, in a week or so if there are no further 0.7 problems, will be 0.8.0 targeting Python 2.6 and upwards and featuring support for reading data from .xlsx files (although not formatting, unless some sponsorship or patches turn up). If you're interested in this, it would be great if you could try out the master branch and let us know if you find any problems: https://github.com/python-excel/xlrd There's also details of all things Python and Excel related here: http://www.python-excel.org/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list
Is python a interpreted or compiled language?
Hi, Is python a interpreted or compiled language? What does happen after this command: python f.py I knew python makes file.pyc file to store the bytecode. For java , .class file is the bytecode file, someone can run that file from any machine. So is the .pyc file executale like java? Can anyone please explain/elaborate the process/order of executing python file with example? Thanks.-- http://mail.python.org/mailman/listinfo/python-list
Re: Is python a interpreted or compiled language?
On Wed, Jun 20, 2012 at 5:30 PM, gmspro wrote: > > Hi, > > Is python a interpreted or compiled language? Like other languages that use a VM bytecode, it's a little bit of both. The actual Python code is compiled into Python bytecode. The bytecode is interpreted. > What does happen after this command: python f.py > > I knew python makes file.pyc file to store the bytecode. For java , .class > file is the bytecode file, someone can run that file from any machine. So is > the .pyc file executale like java? Yes, Python is (mostly) able to run the .pyc file directly without the .py source (although tracebacks will be a bit less informative if the .py is not available). I say "mostly" because, while the bytecode is cross-platform, it is version dependent. A Python 3.x installation may or may not be able to run a bytecode compiled by Python 3.y. > Can anyone please explain/elaborate the process/order of executing python > file with example? Whenever a Python module is imported, the interpreter first checks whether a .pyc is available that has the appropriate "magic number" and is up-to-date (based on its timestamp compared to the corresponding .py file). If it can't find or can't use the .pyc file, then it recompiles the .py file into a .pyc file. Otherwise, it skips the compilation step and just runs the bytecode from the .pyc file. Note though that when a .py file is executed directly (not imported), it does not look for or generate a .pyc file; it just compiles the .py unconditionally in memory and runs the bytecode. If you're interested in the bytecode, you can use the dis module to disassemble functions and other code objects and examine it: >>> import dis >>> def f(x): ... return x + 1 ... >>> dis.dis(f) 2 0 LOAD_FAST0 (x) 3 LOAD_CONST 1 (1) 6 BINARY_ADD 7 RETURN_VALUE Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list
Jython and PYTHONSTARTUP
Does Jython 2.5 honour the PYTHONSTARTUP environment variable? According to my testing, it doesn't. There used to be a page describing the differences between Jython and CPython here: http://www.jython.org/docs/differences.html but it appears to have been eaten by the 404 Monster. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python a interpreted or compiled language?
On 06/20/2012 07:30 PM, gmspro wrote: > Hi, > > Is python a interpreted or compiled language? > What does happen after this command: python f.py > > I knew python makes file.pyc file to store the bytecode. For java , .class > file is the bytecode file, someone can run that file from any machine. So is > the .pyc file executale like java? > > Can anyone please explain/elaborate the process/order of executing python > file with example? > > Thanks. > Ian has given you a good answer. But since you mention java, I'd like to point out a few things that are different between the two environments. He and I are describing CPython; jython and other implementations don't use .pyc files, and they behave differently. java has available a "runtime" environment, for those who don't want or need the compiler. CPython comes with the compiler and the runtime bundled together. Java's classfile remains stable over a number of compiler versions, while CPython doesn't seem to worry about that. Java's classfile has been targeted by a number of other byte code compilers, including jython. Code from any of those libraries may use the java libraries. With java, one has to explicitly compile the java code, while with CPython, the runtime logic compiles imported modules if they're not already compiled. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter binding question
On Wednesday, June 20, 2012 12:07:04 PM UTC-5, Frederic Rentsch wrote:
> [...]
> Googling I chanced on an excellent introduction "Thinking in
> Tkinter" [...] He sets out identifying a common problem with
> tutorials: The problem is that the authors of the books want to rush
> into telling me about all of the widgets in the Tkinter toolbox, but
> never really pause to explain basic concepts. They don't explain how
> to "think in Tkinter".
Well. I have not analyzed this tutorial myself but i can tell you one thing for
sure; most of the confusion regarding Tkinter comes NOT from improperly written
tutorials NO, it is a direct result of the poorly designed Tkinter API itself!
=
Some of the main problems follow:
=
*## 1. Failure to constrain event sequences:*
Tkinter allows users to bind a virtual cornucopia of possible event sequences.
Some say this is a good thing because it allows freedom, i say it is
contributing to unreadable and unmaintainable code bases. There are literally
thousands of possible combinations a user could bind. Sure, this "freedom"
might make the user feel good, but i can guarantee his code will be a spaghetti
mess!
It is my firm belief, that only two Key Events and four Mouse Events should be
allowed binding. Then, the callback should handle the dirty details -- which
could include delegating details to one or many lower worker functions. In the
real world you only need six possible events to process user input:
* KeyPress(keyName)
* KeyRelease(keyName)
* MousePress(x, y, bNum)
* MouseRelease(x, y, bNum)
* MouseMotion(x, y, bNum)
* MouseWheel(direction)
Checking the state of modifiers like Control, Shift, or Alt should be handled
via an event object. Actually, all events should be a subclass of an
EventHandler object.
*## Explicit parent/child relationships needs to be mandatory:*
Tkinter allows users to be lazy and omit the parent of a widget to save a few
keystrokes on tiny little throw away scripts. In the real world, and even in
small GUI applications, you would never want to do such a thing. I believe this
methodology does irreversible damage to a new users brain. He fails to see the
app->subwin->widget hierarchy from day one.
*## 2. Inconsistencies when constructing widgets:*
Most widgets expect a "parent" argument as the first argument, but not the case
for Dialogs and other classes which allow you to pass "parent=blah" as a kw
option. Without a parent, a dialog can not set up a proper transient
relationship OR position itself properly over the correct window. Allowing this
slothful developer behavior contributes to many frustrating user experiences.
*## 3. Inconsistencies between configuring widgets and configuring windows:*
Windows don't have a config method for things like: "title", "size", "etc".
Instead they have methods like win.title("Title") or win.geometry("wxh+x+y");
which again breaks the consistency that is so important in any API! Not to
mention the unessesaryily cryptic nature of a few of these methods.
*## 4. Failure to remove old tutorials from the web that are still teaching
people to code Tkinter GUI's like it's 1991:*
This is a sad result of a dead community. And the few people who are remaining
have become so partisan that nothing can get accomplish except, well, nothing.
Congratulations Guido, are you proud of what you have created? Or rather, or
you proud of what this community had degenerated into? (BTW those are
rhetorical questions.)
I am still hoping beyond hope that some new blood will enter this community
soon and inject some hope for the future. Guido is an old man. He has no
passion anymore. I long for some new blood with a passion for consistency.
People with the intuition required to create intuitive APIs. But most of all.
People who have a "can do" community spirit.
A boy can dream.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Is python a interpreted or compiled language?
On Thu, Jun 21, 2012 at 10:53 AM, Dave Angel wrote: > With java, one has to explicitly compile the java code, while with > CPython, the runtime logic compiles imported modules if they're not > already compiled. Putting it another way: Java's bytecode and source code are two distinct languages, both well documented and separately usable (and with their own distinct limitations - there are things you can do in Java bytecode that you cannot do in Java source). With CPython, the bytecode is an implementation detail and an optimization (once it's parsed your .py file once, a .pyc file can be saved to allow the interpreter to save some effort next time). ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python a interpreted or compiled language?
On Wed, 20 Jun 2012 18:27:53 -0600, Ian Kelly wrote: > On Wed, Jun 20, 2012 at 5:30 PM, gmspro wrote: >> >> Hi, >> >> Is python a interpreted or compiled language? > > Like other languages that use a VM bytecode, it's a little bit of both. > The actual Python code is compiled into Python bytecode. The bytecode > is interpreted. I should point out that the difference between interpreted and compiled is fairly arbitrary and less useful these days. The model for programming languages used to be: Interpreters go over the source code, line by line, executing each line as it is read. If you loop over a line twice, it gets read twice, interpreted twice, and executed twice. Compilers go over the source code once, line by line, interpreting the code once, building machine code which can be directly executed by the hardware. Even back in the 1970s this simple picture was not quite right: it hides a lot of detail. Many "compiled" languages would compile to assembly language for a virtual machine, rather than direct to hardware specific machine code. For example, some Pascal compilers would compile code for a virtual p-machine. Languages like Forth can switch from "compile" mode to "interpret" mode from one command to the next. And of course, machine code itself is interpreted by the hardware, and there are many ways of setting up the machine code (e.g. direct vs indirect threaded code) which may be faster or slower at the expense of more or less memory. So the distinction between compiled and interpreted has always been a bit fuzzy. These days it is a lot fuzzy. Any "compiled" language that includes an eval or exec function must include an interpreter; nearly all interpreters compile code to byte code, and the few that don't usually build a parse tree instead. And then there are Just In Time compilers, which compile to machine code instructions at runtime, giving the flexibility of interpreters with the speed of compilers. An interpreter with a clever enough JIT can be faster than a static compiler, which leads to cases where Python can be faster than C: 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: Re: Is python a interpreted or compiled language?
On 6/20/2012 19:53, Dave Angel wrote: > But since you mention java, I'd like > to point out a few things that are different between the two > environments. He and I are describing CPython; jython and other > implementations don't use .pyc files, and they behave differently. There's one more important difference, which is that the JVM does just-in-time (JIT) compilation of bytecode rather than straight interpretation like CPython does. This basically means that as a program is executing, the JVM will sometimes go through what is a more traditional compilation step and translate its bytecode into machine code rather than just interpret it. It will do this for things it discovers are "hot paths" through the program, where spending some extra time up front (while the program is still executing!) for the compilation and optimization steps is worth it in terms of the speedup. In fact, the JVM may transform a given piece of bytecode several times, applying new optimizations as it discovers that some block is not just important, but *really* important. :-) (Where "important" = "executed a lot.") By my understanding, CPython doesn't do any of this; it always executes the same byte code in the same way, and what it does to the bytecode looks more like an interpreter than a JIT compiler. On the other hand, Jython translates Python to Java bytecode and IronPython translates Python to .Net bytecode (MSIL), so if you use one of those implementations of Python, you are getting a JIT. (Nevertheless my understanding is both tend to be slower than CPython? Not sure about that, and don't know by how much or why.) The new kid on the block is PyPy, which is a JIT engine for Python written in Python itself. But the interesting point is that the (very) old view of "compiled or interpreted" breaks down a lot nowadays; it's closer to a continuum: - pure interpreted - compiled to bytecode, which is then interpreted - JIT compiler (almost always this has a bytecode compilation step though theoretically this isn't necessary) - pure compiled I'd say these categories tend to be qualitative "I know it when I see it" rather than hard divisions. Evan > > java has available a "runtime" environment, for those who don't want or > need the compiler. CPython comes with the compiler and the runtime > bundled together. > > Java's classfile remains stable over a number of compiler versions, > while CPython doesn't seem to worry about that. > > Java's classfile has been targeted by a number of other byte code > compilers, including jython. Code from any of those libraries may use > the java libraries. > > With java, one has to explicitly compile the java code, while with > CPython, the runtime logic compiles imported modules if they're not > already compiled. > signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python a interpreted or compiled language?
On Wed, Jun 20, 2012 at 7:27 PM, Chris Angelico wrote: > Java's bytecode and source code are two distinct languages, both well > documented and separately usable (and with their own distinct > limitations - there are things you can do in Java bytecode that you > cannot do in Java source). I can think of at least one thing you can do in Python 2.x bytecode that you cannot do in Python 2.x source -- writing to nonlocal variables. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python a interpreted or compiled language?
Dave Angel, 21.06.2012 02:53: > On 06/20/2012 07:30 PM, gmspro wrote: >> Is python a interpreted or compiled language? > > Ian has given you a good answer. But since you mention java, I'd like > to point out a few things that are different between the two > environments. He and I are describing CPython; jython and other > implementations don't use .pyc files, and they behave differently. In other words: it's not the language that is interpreted or compiled, it's an implementation that interprets or compiles a language. It may do so in various degrees of interpretation and compilation, such as JIT compilation of otherwise interpreted code. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Can parellelized program run slower than single process program?
from multiprocessing import Pool from itertools import product def sym(lst): x,y=lst tmp=x*y if rec(tmp): return tmp else: return None def rec(num): num=str(num) if num == "".join(reversed(num)):return True else:return False if __name__ == "__main__": pool=Pool(processes=8) lst=product(xrange(100,1000),repeat=2) rst=pool.map(sym,lst) #rst=sym(lst) print max(rst) in my old computer(2006), when run it on single process, it takes 2 seconds but using multiprocessing.pool, it takes almost 8 or 9 seconds is it possible? -- http://mail.python.org/mailman/listinfo/python-list
Re: Can parellelized program run slower than single process program?
The multiprocessing module allows the programmer to fully leverage *multiple * processors on a given machine (python docs). This allows the operating system to take advantage of any parallelism inherent in the hardware design. If you are using the module on non-multiprocessor machines, I think you are not using it to its full capability, and the module's overhead will just slow down your code. Aldrich On Thu, Jun 21, 2012 at 12:05 AM, Yesterday Paid wrote: > from multiprocessing import Pool > from itertools import product > > def sym(lst): >x,y=lst >tmp=x*y >if rec(tmp): >return tmp >else: >return None > > def rec(num): >num=str(num) >if num == "".join(reversed(num)):return True >else:return False > > if __name__ == "__main__": >pool=Pool(processes=8) >lst=product(xrange(100,1000),repeat=2) >rst=pool.map(sym,lst) >#rst=sym(lst) >print max(rst) > > > in my old computer(2006), > when run it on single process, it takes 2 seconds > but using multiprocessing.pool, it takes almost 8 or 9 seconds > is it possible? > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Can parellelized program run slower than single process program?
On 06/21/2012 01:05 AM, Yesterday Paid wrote: > from multiprocessing import Pool > from itertools import product > > def sym(lst): > x,y=lst > tmp=x*y > if rec(tmp): > return tmp > else: > return None > > def rec(num): > num=str(num) > if num == "".join(reversed(num)):return True > else:return False Those last two lines could be replaced by simply return num == num[::-1] which should be much faster. I haven't checked that, however. > if __name__ == "__main__": > pool=Pool(processes=8) > lst=product(xrange(100,1000),repeat=2) > rst=pool.map(sym,lst) > #rst=sym(lst) > print max(rst) > > > in my old computer(2006), > when run it on single process, it takes 2 seconds > but using multiprocessing.pool, it takes almost 8 or 9 seconds > is it possible? Sure, it's possible. Neither multithreading nor multiprocessing will help a CPU-bound program if you don' t have multiple processors to run it on. All you have is the overhead of all the pickling and unpickling, to get data between processes, with no reduction in useful processing time. I suspect that in your case, the amount of work you're giving each process is small, compared to the work that the multiprocessing module is doing getting the processes to cooperate. Now, if you had a quad CPU (8 hyperthreads), and if the work that each process were doing were non-trivial, then i'd expect the balance to go in the other direction. Or if the operation involved I/O or other non-CPU-intensive work. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
