Re: Will IronPython / WPF work on Mac OS X?

2014-08-04 Thread Benjamin Kaplan
On Aug 4, 2014 6:23 AM,  wrote:
>
> Hello,
> I am thinking of using IronPython to build an Python application. Using
WPF in Visual Studio to draw the GUI and create the XAML.  Can I then run
this Python application on a Mac OS X (10.8)?
> Thanks.
> --

Nope. IronPython on Mac runs on top of Mono, so it has access to all the
libraries that Mono supports. That means there's no support for WPF except
for the subset that Silverlight supported (See
http://www.mono-project.com/wpf ).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is the difference between 32 and 64 bit Python on Windows 7 64 bit?

2014-05-11 Thread Benjamin Kaplan
On Sat, May 10, 2014 at 11:56 PM, Ross Gayler  wrote:
>
> Hi,
>
> I want to install Python on a PC with 16GB of RAM and the 64 bit version of 
> Windows 7.
> I want Python to be able to use as much as possible of the RAM.
>
> When I install the 64 bit version of Python I find that sys.maxint == 2**31  
> - 1
> Whereas the Pythpon installed on my 64 bit linux system returns sys.maxint == 
> 2**63 - 1.
>

That comes from the underlying C implementation. 64-bit MSVC still has
long int as 32-bit. You need to specify long long int to get a 64-bit
number even on a 64-bit compiler. Microsoft is a little nuts on the
backwards compatiblity.


> It looks to me as though 32 and 64 bit versions of Python on 64 bit Windows 
> are both really 32 bit Python, differing only in how they interact with 
> Windows. So I wouldn't expect 64 bit Python running on 64 bit Windows to 
> allow the large data struictures I could have with 64 bit Python running on 
> 64 bit linux.
>
> Is that true?I have spent a couple of hours searching for a definitive 
> description of the difference between the 32 and 64 bit versions of Python 
> for Windows and haven't found anything.
>

long int (the size of an integer) != size_t (the size of an object).
64-bit Python still uses 64-bit pointers so it can still address more
than 4GB of memory. It just rolls over into longs after 32-bit int max
instead of after 64-bit int max.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functions help

2014-02-23 Thread Benjamin Kaplan
On Sun, Feb 23, 2014 at 5:39 PM, alex23  wrote:
> On 24/02/2014 11:09 AM, Mark Lawrence wrote:
>>
>> On 24/02/2014 00:55, alex23 wrote:
>>>
>>>
>>>  for _ in range(5):
>>>  func()
>>
>>
>> the obvious indentation error above
>
>
> Stupid cut&paste :(
> --

Your message came through fine for me (viewing as mailing list in
gmail). Mark's client must be dropping spaces.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python import error

2013-12-10 Thread Benjamin Kaplan
On Tue, Dec 10, 2013 at 9:45 PM,   wrote:
> On Wednesday, December 11, 2013 10:23:34 AM UTC+5:30, John Gordon wrote:
>> In <93405ea9-6faf-4a09-9fd9-ed264e313...@googlegroups.com> 
>> smilesonisa...@gmail.com writes:
>>
>>
>>
>> >   File "aaa.py", line 5, in 
>>
>> > from ccc.ddd import sss
>>
>> > ImportError: No module named ccc.ddd
>>
>>
>>
>> > directory structure as follows:
>>
>>
>>
>> > ccc
>>
>> > |
>>
>> >  ddd
>>
>> >|
>>
>> > aaa.py
>>
>> > sss.py
>>
>>
>>
>> A python file isn't importable unless the directory also contains a file
>>
>> named __init__.py .
>>
>>
>>
>> Try making __init__.py files in the ccc and ddd directories.  If you
>>
>> don't know what to put in them, just leave them blank.
>>
>>
>> It is having __init__.py as blank in ccc and ddd directories. But it still 
>> doesnot work.
>> --


What directory are you in when you execute the script? Python doesn't
look up for packages so if you're in ddd and calling "python aaa.py",
Python doesn't know about the ccc package. You'd just import sss, or
add the parent directory of ccc to sys.path.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python programming help

2013-12-08 Thread Benjamin Kaplan
On Sun, Dec 8, 2013 at 10:32 AM,  wrote:
>
> On Sunday, December 8, 2013 6:27:34 PM UTC, bob gailer wrote:
> > On 12/8/2013 12:59 PM, rafaella...@gmail.com wrote:
> >
> > > i have a dictionary with names and ages for each name. I want to write a 
> > > function that takes in an age and returns the names of all the people who 
> > > are that age.
> >
> > > please help
> >
> > Welcome to the python list. Thanks for posting a question.
> >
> >
> >
> > If you were hoping for one of us to write the program for you ... well
> >
> > that's not what we do on this list.
> >
> >
> >
> > Please post the code you have so far and tell us exactly where you need
> >
> > help.
> >
> >
> >
> > Also tell us what version of Python, what OS, and what you use to write
> >
> > and run Python programs.
>
> name = ['Alice', 'Bob', 'Cathy', 'Dan', 'Ed', 'Frank', 'Gary', 'Helen', 
> 'Irene', 'Jack', 'Kelly', 'Larry']
> age = [20, 21, 18, 18, 19, 20, 20, 19, 19, 19, 22, 19]
> dic={}
> def combine_lists(name,age):
> for i in range(len(name)):
> dic[name[i]]= age[i]
> combine_lists(name,age)
> print dic
>
> def people(age):
> people=lambda age: [name for name in dic if dic[name]==age]
>
> people(20)
>
>
>
>
> this is the code i have so far(with the help of the first post ;p). i 
> understand how a function and a dictionary works and what I'm asked to find. 
> but i don't get the lambda age part. and this code doesn't give me any result
>
>

To return a value from a function, you need to use the "return"
statement with the value you want to pass back out. You're not doing
that here. Also, you're using a lot of shorthand stuff that you should
probably avoid until you're more comfortable with the language

* Lambda is shorthand for a function. foo = lambda bar : bar + 2 is
the same thing as the function
def foo(bar) :
return bar + 2

* a list comprehension is short-hand for a loop. spam = [foo for foo
in bar if baz(foo)]  is the same thing as
spam = []
for foo in bar :
if baz(foo) :
spam.append(foo)

You don't need a lambda here- just call the code that you need to call directly.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying tcompile an use the Python 3.4a

2013-11-14 Thread Benjamin Kaplan
On Nov 14, 2013 5:55 AM, "Nick the Gr33k"  wrote:
>
> Will someone please tell me how to install 'pip'
>
> My website is not working because modules are missing and the only way i
can install them is by installing python's module manager 'pip'
>
> but 'yum install python-pip' fails.
>
> How would i install the damn thing?
>
> These action should be done via package managers but i wasn't ven able to
install python 3.4a like that, i had to compile it form source when the
easy thing to do was "yum install python3"
>
> what wrong with this 'yum' manager?
> --
> https://mail.python.org/mailman/listinfo/python-list

package managers assume that they are the only thing installing software on
your system. Any python related package you install through yum will only
be compiled for and installed to the versions of python that you can get
through yum. If you want to compile python outside they package manager,
you'll also have to install all the libraries outside of the package
manager.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Benjamin Kaplan
On Tue, Oct 22, 2013 at 8:04 AM, Mark Janssen  wrote:
> I love it.  Watch this...
>
> [context]
 A language specification in BNF is just syntax. It doesn't say anything
 about semantics. So how could this be used to produce executable C code
 for a program? BNF is used to produce parsers. But a parser isn't
 sufficient.
>>>
>>> A C program is just syntax also.  How does the compiler generate
>>> executable machine code?  Extrapolate into a Python front-end to C.
>
> [Dave Angel responds:]
>> Did you even read the paragraph you quoted above?  The BNF specification
>> does NOT completely describe a language, it only defines its syntax.
>
> [Steven D'Aprano responds:]
>> Like every other language, C programs are certainly not *just* syntax.
>> Here is some syntax:
>>
>> &foo bar^ :=
>
> Now, I don't know where y'all were taught Computer Science, but BNF
> specifies not only syntax (which would be the *tokens* of a language),
> but also its *grammar*;  how syntax relates to linguistic categories
> like keywords, and tokens relate to each other.
>
> Dave is claiming that BNF only defines the syntax of a language, but
> then Stephen goes on to supply some syntax that a BNF specification of
> the language would not allow (even though Steven calls it "syntax"
> which is what BNF in Dave's claim parses).
>
> So which of you is confused?  I ask that in the inclusive (not
> exclusive OR) sense ;^)  <-- face says "both".
>

I don't know where you were taught English, but syntax is " the way in
which linguistic elements (as words) are put together to form
constituents (as phrases or clauses) ", not the set of valid words
(tokens) in a language. A grammar, such as those grammars written in
BNF, describe the rules for the syntax of a language. And, as Steven
said, it still doesn't describe the semantics of a language, which is
the set of instructions described by the syntax.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python GUI?

2013-09-17 Thread Benjamin Kaplan
On Tue, Sep 17, 2013 at 9:51 AM, rusi  wrote:
> On Tuesday, September 17, 2013 9:49:28 PM UTC+5:30, Benjamin Kaplan wrote:
>> On Tue, Sep 17, 2013 at 7:55 AM, rusi  wrote:
>>
>> > On Thursday, September 12, 2013 10:21:49 PM UTC+5:30, Benjamin Kaplan 
>> > wrote:
>>
>> >
>> >> The main difference between wx and qt is that qt looks native on every 
>> >> platform
>> >> while wx *is* native on every platform (it uses native controls wherever
>> >> possible). This means that wx integrates into the OS better, but your 
>> >> also more
>> >> likely to need OS-specific tweaks in wx, at least from my experience from 
>> >> a few
>> >> years ago.
>> >
>> > For someone who is GUI-challenged, can you please expand on that a bit?
>> > --
>>
>> Sure. Every platform provides its own GUI library (Cocoa on Mac OS X,
>> Win32 on Windows). Other programs that want to hook into yours, such
>> as screen readers, are familiar with the platform's native GUI
>> elements- it knows what a Win32 combo box is, and it knows how to read
>> the text inside it.
>>
>>
>> The other way to make a GUI is to take a blank canvas and draw on it
>> yourself. This is more flexible and provides a more consistent
>> experience across platforms, but unless you specifically go out of
>> your way to provide hooks for other programs to jump in, all they see
>> is a bunch of pixels on the screen. In addition, drawing your own
>> stuff won't necessarily give you the "normal for the operating system"
>> behavior on other things, like tab behavior. It's possible for
>> non-native GUI environments to mimic this behavior (and QT does a
>> pretty good job of this), but there's always going to be little things
>> that seem a bit off.
>
> Thanks for the explanation. However I am not able to square it up:
>
> You seem to be saying that QT draws on a blank canvas rather than calling out 
> to the OS library.
> You also seem to be saying that QT (for the most part) Does the Right Thing 
> for each platform.
> --

Right. The QT developers have been working for years to get their
controls to quack like the native ones, even though they aren't
native. They started from controls that looked and worked the same on
all platforms and have been trying to get them to play nicely with the
environment they're running in. wx has been working from the opposite
direction- they started with wrapping the native API and have been
working on getting their API to make programs come out the same even
when using different underlying toolkits. When I used wx about 5 years
ago, some of the layout got messed up when we first ran the program
(developed on Linux/GTK+)  on a Mac because of some differences
between how Carbon and GTK+ draw their controls.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python GUI?

2013-09-17 Thread Benjamin Kaplan
On Tue, Sep 17, 2013 at 7:55 AM, rusi  wrote:
> On Thursday, September 12, 2013 10:21:49 PM UTC+5:30, Benjamin Kaplan wrote:
>
>> The main difference between wx and qt is that qt looks native on every 
>> platform
>> while wx *is* native on every platform (it uses native controls wherever
>> possible). This means that wx integrates into the OS better, but your also 
>> more
>> likely to need OS-specific tweaks in wx, at least from my experience from a 
>> few
>> years ago.
>
> For someone who is GUI-challenged, can you please expand on that a bit?
> --

Sure. Every platform provides its own GUI library (Cocoa on Mac OS X,
Win32 on Windows). Other programs that want to hook into yours, such
as screen readers, are familiar with the platform's native GUI
elements- it knows what a Win32 combo box is, and it knows how to read
the text inside it.

The other way to make a GUI is to take a blank canvas and draw on it
yourself. This is more flexible and provides a more consistent
experience across platforms, but unless you specifically go out of
your way to provide hooks for other programs to jump in, all they see
is a bunch of pixels on the screen. In addition, drawing your own
stuff won't necessarily give you the "normal for the operating system"
behavior on other things, like tab behavior. It's possible for
non-native GUI environments to mimic this behavior (and QT does a
pretty good job of this), but there's always going to be little things
that seem a bit off.

The situation is a bit more complicated because QT is the native
toolkit on KDE, so in that environment, QT will be more "correct" than
wx, which would be using GTK if present and plain X11 if it isn't.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python GUI?

2013-09-12 Thread Benjamin Kaplan
On Sep 12, 2013 9:06 AM,  wrote:
>
> On Thursday, September 12, 2013 6:05:14 AM UTC+1, Michael Torrie wrote:
> > On 09/11/2013 02:55 PM, eamonn...@gmail.com wrote:
> >
> > > PyQT -- You have a GUI designer, so I'm not going to count that
> >
> > What do you mean?  Gtk has a GUI designer too.  what of it
> >
> > > I, personally, really like wxPython, but I also really like Tkinter.
> >
> > > I've messed with PyGTK, but I'd choose wxPython over it.
> >
> > Not me.  wxWidgets' event model is way too MFC-esque for me.  Does it
> >
> > still use event numbers that you define?  Shudder.
> >
> > Gtk and Qt's method of signals and slots is by far the most powerful and
> > flexible.
> >
> > > Have you got anything to say on what one I should be using(excluding
> >
> > > PyQT because it has a D&D designer >:( )? Is Tkinter really dead?
> >
> > > Should I stick with wxPython?
> > I still don't understand why you are excluding Qt.  All modern toolkits
> >
> > are heading towards imperative GUI design.  With Gtk I use Glade and
> >
> > GtkBuilder.  My GUI is in a nice XML file that gets loaded and
> >
> > manipulated by my python class.  It's extremely clean.  And in the case
> >
> > of compiled programming, you don't have to recompile just to tweak
> >
> > something like a layout.
> > At the moment if someone were to come in from scratch and ask what GUI
> > toolkit to use, I would answer Qt with PySide.  It's the most
> > cross-platform of all the toolkits, and it's one of the most mature.
> >
> > Gtk is also good, but Windows and Mac support is always lagging behind
> >
> > X11, and it's not as good at fitting into the native look and feel.
>
> > > Also, with wxPython, it has kind of a "flow" layout like JFrame,
> >
> > > whereas it will adjust it's layout to look like a native Mac App,
> >
> > > Windows app or Linux App, correct? It'll look almost identical,
> >
> > > right? Not that it matters, I'm just curious! :D
> >
> >
> >
> > Possibly.  I know Qt and Gtk both can flip the button orders, etc to
> >
> > look more native.  And all good toolkits give you layout managers so you
> >
> > never have to resort to fixed layouts.  Qt's layout system is very
> >
> > different than Gtk's, but once you get the feel of it (use the Qt
> >
> > Designer program!), it makes a lot of sense.
>
> I didn't realise GTK has a GUI designer too :(
>
> I don't like it when you can D&D to position things. I don't understand
why someone wouldn't want to write the positioning code, and have fun with
the debugging. That's the best part about writing a program, in my opinion.
I'm against D&D with programming, and I'm not sure why.
> --
>

There are gui designers for wx as well. Doesn't mean you ever have to use
any of them (although I wouldn't want to write windows forms code by hand).
I do find it generally nicer to work with the markup formats (xrc for wx,
xaml for wpf, and so on) rather than trying to describe a gui in a
programming language.

The main difference between wx and qt is that qt looks native on every
platform while wx *is* native on every platform (it uses native controls
wherever possible). This means that wx integrates into the OS better, but
your also more likely to need OS-specific tweaks in wx, at least from my
experience from a few years ago.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Language design

2013-09-11 Thread Benjamin Kaplan
On Wed, Sep 11, 2013 at 5:37 PM, Mark Janssen  wrote:
>> Unicode is not 16-bit any more than ASCII is 8-bit. And you used the
>> word "encod[e]", which is the standard way to turn Unicode into bytes
>> anyway. No, a Unicode string is a series of codepoints - it's most
>> similar to a list of ints than to a stream of bytes.
>
> Okay, now you're in blah, blah land.
>
> --mark
> --

There's no such thing as 16-bit Unicode. Unicode is a sequence of
characters, not a sequence of bytes. It's an abstract thing. To work
with it on a computer, you need to use a byte encoding because
computers don't deal with with abstract things. UTF-16 is one encoding
method that can map any character defined in Unicode to a sequence of
bytes. UTF-16 isn't Unicode, it's just a function that maps a byte
string to a character string. Python's unicode class is a character
string- as far as the user is concerned, it's made up of those
abstract "character" things and not bytes at all.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: NameError: global name '' is not defined , but a bit differences

2013-09-04 Thread Benjamin Kaplan
On Wed, Sep 4, 2013 at 9:17 PM, Mohsen Pahlevanzadeh
 wrote:
> Dear all ,
>
> i get the error :
>
> NameError: global name 'ui' is not defined
>
> Complete question is at :
> http://stackoverflow.com/questions/18627608/nameerror-global-name-is-not-defined-but-differences
>
> Before answering, Thank you for your attention...!
>
>
> Yours,
> Mohsen
>
>

Please don't just post a link to Stack Overflow for your questions. It
means that if Stack Overflow ever shuts down, this question is useless
to anyone else looking at this post and also adds an extra step to
anyone on this list wanting to answer your question- we're helping you
in our spare time because we want to help people with these things.
Please don't make us do extra work to help you.

Just a note- doing a "from module import *" is considered poor coding
style because it makes it difficult to figure out where all the names
are coming from, especially if you start doing multiple import *s in a
single code file. Either explicitly import the names you need ("from
ui.interface.interface import InterfaceCodes") or import the module
without adding the names to the local namespace ("import
ui.interface.interface")
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to exit a cgi file after a download

2013-09-04 Thread Benjamin Kaplan
On Sep 4, 2013 1:29 PM, "Ferrous Cranus"  wrote:
>
> Python help.
>
> I use the following code in a cgi file
> to give the client a download link to
> download a file.
>
> ---
>
> print "%s" % (' Down
> Load ')
>
> 
>
> A click on "Down Load" opens a pop up browser
> window which allows the user to choose where
> to download the "Setup.zip" file, then after
> the download, the pop up window closes.
>
> My problem is that I want the cgi form, which
> contains the link, to also close after the
> download.  The only way I can figure out to
> close the cgi window is to give the user a
> button to close it.
>
> Without closing it, the client can download
> again and forever if they choose to because
> the cgi window is open and the link is still
> active.
>
> I am trying to find a way to close the cgi
> file or call another file after the download
> without adding a close button and asking the
> client to close the window.
>
> jd
>
>

There is no such thing as a "cgi form" or "cgi window". Your cgi script
runs when the user requests a Web page, generates a page, and then ends. At
that point, python has stopped running. If your want the client's browser
window to close, that's not a python problem. If you want to invalidate the
download link after one successful download, you'll have to add a unique
identifier to the url and keep track of which identifiers are still valid.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New way of writing socket servers in #Linux kernel 3.9 (and in #Python too)

2013-08-24 Thread Benjamin Kaplan
On Sat, Aug 24, 2013 at 7:08 PM, Michael Torrie  wrote:
> #Linux, #Python?  This this hash tag stuff is getting out of hand, don't
> you think?

Didn't you hear? In an effort to redefine itself for the modern
Internet, Usenet is adding support for hash tags and limiting posts to
140 characters because kids these days just don't want to read
anything longer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List getting extended when assigned to itself

2013-08-24 Thread Benjamin Kaplan
On Sat, Aug 24, 2013 at 8:52 PM, Krishnan Shankar
 wrote:
> Hi Python Friends,
>
> I came across an example which is as below,
>
 var = [1, 12, 123, 1234]
 var
> [1, 12, 123, 1234]
 var[:0]
> []
 var[:0] = var
 var
> [1, 12, 123, 1234, 1, 12, 123, 1234]

>
> Here in var[:0] = var we are assigning an entire list to the beginning of
> itself. So shouldn't it be something like,
>
> [[1, 12, 123, 1234], 1, 12, 123, 1234]
>
> It happens when we do the below,
>
 var = [1, 12, 123, 1234]
 var[0] = var
 var
> [[...], 12, 123, 1234]

>
> Literally var[0] = var and var[:0] = var almost meens the same. But why is
> the difference in output? Can anyone explain what happens when slicing
> assignment and direct assignment.

Are you sure they're almost the same?

>>> var[0]
1
>>> var[:0]
[]

One's a list and one is an integer. It's hard for them to be any more
different. var[0] means that you should be setting an element of the
list. var[:0] says you want to update a piece of the list, not an
element inside it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread Benjamin Kaplan
On Sat, Aug 24, 2013 at 9:47 AM, David M. Cotter  wrote:
>
> > What _are_ you using?
> i have scripts in a file, that i am invoking into my embedded python within a 
> C++ program.  there is no terminal involved.  the "print" statement has been 
> redirected (via sys.stdout) to my custom print class, which does not specify 
> "encoding", so i tried the suggestion above to set it:
>
> static const char *s_RedirectScript =
> "import " kEmbeddedModuleName "\n"
> "import sys\n"
> "\n"
> "class CustomPrintClass:\n"
> "   def write(self, stuff):\n"
> "   " kEmbeddedModuleName "." kCustomPrint "(stuff)\n"
> "class CustomErrClass:\n"
> "   def write(self, stuff):\n"
> "   " kEmbeddedModuleName "." kCustomErr "(stuff)\n"
> "sys.stdout = CustomPrintClass()\n"
> "sys.stderr = CustomErrClass()\n"
> "sys.stdout.encoding = 'UTF-8'\n"
> "sys.stderr.encoding = 'UTF-8'\n";
>
>
> but it didn't help.
>
> I'm still getting back a string that is a utf-8 string of characters that, if 
> converted to "macRoman" and then interpreted as UTF8, shows the original, 
> correct string.  who is specifying macRoman, and where, and how do i tell 
> whoever that is that i really *really* want utf8?
> --

If you're running this from a C++ program, then you aren't getting
back characters. You're getting back bytes. If you treat them as
UTF-8, they'll work properly. The only thing wrong is the text editor
you're using to open the file afterwards- since you aren't specifying
an encoding, it's assuming MacRoman. You can try putting the UTF-8 BOM
(it's not really a BOM) at the front of the file- the bytes 0xEF 0xBB
0xBF are used by some editors to identify a file as UTF-8.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Resolving import errors reported by PyLint in modules using Python.NET

2013-08-08 Thread Benjamin Kaplan
On Thu, Aug 8, 2013 at 10:17 PM,   wrote:
> PyLint can't figure out imports of .NET code being referenced in my Python 
> scripts that use Python.NET.  I can kind of see why; you have to evaluate 
> some clr.AddReference calls for the imports to even succeed.  I wonder if I 
> have any recourse.  Generally, to import a DLL you have to do a few things.  
> I guess for an example I'll import a .NET string:
>
> 
> import clr# Python .NET common-language runtime module, the important 
> part of it all
>
> clr.AddReference("System")
> from System import String   # .NET System.String
>
> can = String("Spam")
> 
>
> PyLint is not amused:
> F:  4, 0: Unable to import 'System' (import-error)
>
> I wondered if there were any tricks to make it work.  I don't want to just 
> ignore import-error, either by explicitly telling pylint to ignore them, or 
> be getting complacent in seeing them all the time.  I am also kind of curious 
> if PyLint will expose new problems if it's able to figure out more things 
> after successfully  passing the imports.  I wouldn't really know.

Are you using Python.NET or IronPython? IronPython is reasonably well
supported, and it looks like there's a patch you can use to get PyLint
working on it (see
http://mail.python.org/pipermail/ironpython-users/2012-June/016099.html
). Not sure what's going on with Python.NET
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GeoIP2 for retrieving city and region ?

2013-07-15 Thread Benjamin Kaplan
On Sat, Jul 13, 2013 at 10:43 AM, Νικόλας  wrote:
> Στις 13/7/2013 7:54 μμ, ο/η Dennis Lee Bieber έγραψε:
>>
>> Are you paying for a fixed IP number? I suspect you are if you
>> were
>> running a world-accessible server.
>>
>> Obviously a fixed IP will be tied to a fixed connection and
>> thereby to
>> a fixed location which can be provided to a location database.
>>
>> But most of us have DHCP assigned IP numbers, which change
>> everytime we
>> reboot our connection (or even when the DHCP lease expires -- which may be
>> daily).
>
>
> Same networking scheme for me too, dynamic that is.
>
> Every time the DHCP lease expires or i reboot the router i get a new ip
> address but every time the link i provided states accurately that my ip
> address is from Thessaloníki and not Europe/Athens which is were my ISP
> location is.
>
> Not to mention that in facebook, no matter the way i'am joining, via
> smartphone, tablet, laptop it always pinpoints my exact location.
>
> But yes, i can understand your skepticism.
> An ip address can move anywhere while remaining connected to the same ISP,
> just like a networking device in the house, remains connected to the same
> router while changing rooms or even floors, or even buildings.
>
> But then how do you explain the fact that
> http://www.maxmind.com/en/geoip_demo
> pinpointed Thessaloníki and not Athens and for 2 friends of mine that use
> the same ISP as me but live in different cities also accurately identified
> their locations too?
>

It's not telling you where your ISP is headquartered. It's telling you
where the servers that you're connecting to are. In your case, you're
connecting to servers that your Athens-based ISP has in a Thessaloniki
datacenter. The only way to get an accurate location is to use
something other than IP- phones like to use a combination of their
GPS, a map of the cell phone towers, and a map of wi-fi hotspots (this
is one of the things that Google's StreetView cars log as they drive).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Explain your acronyms (RSI?)

2013-07-06 Thread Benjamin Kaplan
On Sat, Jul 6, 2013 at 12:38 PM, Terry Reedy  wrote:
> "rms has crippling RSI" (anonymous, as quoted by Skip).
>
> I suspect that 'rms' = Richard M Stallman (but why lower case? to insult
> him?). I 'know' that RSI = Roberts Space Industries, a game company whose
> Kickstarter project I supported. Whoops, wrong context. How about 'Richard
> Stallman Insanity' (his personal form of megalomania)? That makes the phrase
> is a claim I have read others making.
>
> Lets continue and see if that interpretation works. "should indicate that
> emacs' ergonomics is not right". Aha! Anonymous believes that using his own
> invention, emacs, is what drove Richard crazy. He would not be the first
> self invention victim.
>
> But Skip mentions 'worse for wrists'. So RSI must be a physical rather than
> mental condition. Does 'I' instead stand for Inoperability?, Instability?,
> or what?
>
> Let us try Google. Type in RSI and it offers 'RSI medications' as a choice.
> Sound good, as it will eliminate all the companies with those initials. The
> two standard medical meanings of RSI seem to be Rapid Sequence Intubation
> and Rapid Sequence Induction. But those are procedures, not chronic
> syndromes. So I still do not know what the original poster, as quoted by
> Skip, meant.
>
> --
> Terry Jan Reedy

RSI is a repetitive stress injury.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-05 Thread Benjamin Kaplan
On Jul 5, 2013 12:12 AM, "Lele Gaifax"  wrote:
>
> Νίκος Gr33k  writes:
>
> > try:
> >   host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
> > except Exception as e:
> >   host = "Reverse DNS Failed"
> >
> > How can the above code not be able to reeverse dns any more and it
> > falls back to  the failed string?
>
> The only way to know is actually printing out the exception, either to
> stderr, or better using the logging facility, as I suggested.
>
> FYI, your code above is (almost) exactly equivalent to the simpler
>
> try:
> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
> except:
> host = "Reverse DNS Failed"
>
> ciao, lele.
>

They aren't equivalent. "except Exception" won't catch KeyboardInterrupt or
SystemExit or a few others that you really don't want to catch in a generic
error handler. You should almost never have a bare except.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Importing modules into IronPython

2013-07-03 Thread Benjamin Kaplan
On Wed, Jul 3, 2013 at 3:05 PM, HighBeliever  wrote:
> Hi, I have to shift a Python 2.7 program to run in Windows. Doing that has 
> forced me to use IronPython because my program is dependent on a .dll file 
> that uses .NET framework.
>
> I moved all my code to Iron Python and modified it to work with the dll. But 
> I cant import PyQt4 module into the project. Is there a way I can do that? 
> Please Help.
> --

Generally, extensions that aren't pure Python can only be used with
the interpreter they were designed for. There has been some attempt to
get CPython extensions working under IronPython (there's a tracking
issue on IronPython's bug tracker-
http://ironpython.codeplex.com/workitem/11333), but I don't know how
well it works.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to tell Script to use pythonw.exe ?

2013-07-03 Thread Benjamin Kaplan
On Jul 3, 2013 8:27 AM, "Νίκος"  wrote:
>
> Στις 3/7/2013 6:43 πμ, ο/η Tim Roberts έγραψε:
>
>> goldtech  wrote:
>>>
>>>
>>> I just changed the file extension of the script file from .py to .pyw
>>> and it uses pythonw.exe. I didn't read it anywhere, just intuited it
>>> and tried it. Python has some very smart people working the language...
>>
>>
>> While your statement is true, that's not what happened here.
>>
>> Windows has long had the ability to associate a file extension with a
>> handler.  If you start a command shell, the "assoc" command tells you the
>> program type associated with an extension, and the "ftype" command tells
>> you the command line that will be executed for that program type.  On my
>> box:
>>
>> C:\tmp>assoc .py
>> .py=Python
>>
>> C:\tmp>ftype Python
>> Python="C:\Apps\Python27\Python.exe" "%1" %*
>>
>> C:\tmp>assoc .pyw
>> .pyw=Python.NoConFile
>>
>> C:\tmp>ftype Python.NoConFile
>> Python.NoConFile="C:\Apps\Python27\Pythonw.exe" "%1" %*
>>
>> You can create your own, if you want.  If you want files with a .script
>> extension to run PythonW, you can type:
>>
>>  assoc .script=Python.NoConFile
>>
> My associations are broken, bt i only care for open web pages with Chrome
instead of IE, so i sued your method:
>
>
> C:\Windows\system32>assoc .html=Chrome
> .html=Chrome
>
> C:\Windows\system32>ftype
Chrome="C:\Users\Ferrous\AppData\Local\Google\Chrome\Application\chrome.exe"
%1
>
>
Chrome="C:\Users\Ferrous\AppData\Local\Google\Chrome\Application\chrome.exe"
%1
>
> but still when i click a link IE keeps popping up isntead of Chrome.
> Any ideas why?

Because your links don't open files. They send requests to an http server
for data. And IE is the program designated to send http requests. Just use
the browser's "make this the default" button.
> --
> What is now proved was at first only imagined
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this PEP-able? fwhile

2013-06-24 Thread Benjamin Kaplan
On Mon, Jun 24, 2013 at 8:54 PM, Chris Angelico  wrote:
> On Tue, Jun 25, 2013 at 12:01 PM, rusi  wrote:
>> On Tuesday, June 25, 2013 3:08:57 AM UTC+5:30, Chris Angelico wrote:
>>> On Tue, Jun 25, 2013 at 5:52 AM,  <> wrote:
>>>
>>> > (NOTE:  Many people are being taught to avoid 'break' and 'continue' at 
>>> > all
>>> > costs...
>>>
>>> Why? Why on earth should break/continue be avoided?
>>
>> Because breaks and continues are just goto-in-disguise?
>>
>> [Well so is while and if and function-call and... Who is to say that?]
>
> And that's still not a reason imho. You've just pointed out that
> they're all control-flow. :)
>
> ChrisA

The reason I was given (which I promptly ignored, of course) is that
it's "best practice" to only have one exit point for a block of code.
Only one way of terminating your loop, only one "return" per function,
never use exceptions, etc. I think it originally came about as a way
to make sure that your clean-up code was called (and to make it easier
for code reviewers to make sure your clean up code was called) and
then started being passed around as a rule among programming teachers
who didn't have any experience outside the classroom.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Benjamin Kaplan
On Mon, Jun 17, 2013 at 8:55 AM, Simpleton  wrote:
> On 17/6/2013 5:22 μμ, Terry Reedy wrote:
>>
>> On 6/17/2013 7:34 AM, Simpleton wrote:
>>>
>>> On 17/6/2013 9:51 πμ, Steven D'Aprano wrote:

 Now, in languages like Python, Ruby, Java, and many others, there is no
 table of memory addresses. Instead, there is a namespace, which is an
 association between some name and some value:

 global namespace:
  x --> 23
  y --> "hello world"
>>>
>>>
>>> First of all thanks for the excellent and detailed explanation Steven.
>>>
>>> As for namespace:
>>>
>>> a = 5
>>>
>>> 1. a is associated to some memory location
>>> 2. the latter holds value 5
>>
>>
>> This is backwards. If the interpreter puts 5 in a *permanent* 'memory
>> location' (which is not required by the language!), then it can
>> associate 'a' with 5 by associating it with the memory location. CPython
>> does this, but some other computer implementations do not.
>
>
> Please tell me how do i need to understand the sentence
> 'a' is being associated with number 5 in detail.
>
> Why don't we access the desired value we want to, by referencing to that
> value's memory location directly instead of using namespaces wich is an
> indirect call?
>
> i feel we have 3 things here
>
> a , memory address of a stored value, actual stored value
>
>>> So is it safe to say that in Python a == &a ? (& stands for memory
>>> address)
>>>
>>> is the above correct?
>>
>>
>> When you interpret Python code, do you put data in locations with
>> integer addresses?
>
>
> I lost you here.
>

You're confusing the way in which the CPython interpreter is written
with the way the Python language is defined. Yes, the CPython
interpreter puts 5 into a numbered memory location when creating the
object. But the Nikos Python Interpreter (which is a completely valid,
although quite buggy, Python interpreter that uses your head to
interpret the code) should not be using numbered memory locations.

Forget about memory locations. Memory locations don't exist. Let's use
the pen-and-paper Python interpreter. On the left side of the paper,
we'll write down the names. On the rest of the paper, we'll write down
the objects.

When I do "x =[]", I make a new list (which means I write down []
somewhere in the middle of the page), I create the name "x" (which
means I write down an "x" on the left side of the page), and then I
draw an arrow pointing from the x to the [].
(sorry if my drawing doesn't line up in your email/news client- I'll
try to make it line up correctly with a monospace font)

|  x --> []|
|  |
|  |


Now, When we do y = x, the right side of the equation is evaluated
(which gives us the object currently bound to the name x) and it is
then given the newly created name "y"

|  x --> []|
| ^|
|   y ||


When we do x.append(3), the object that x refers to is modified. This
is seen by both x and y because they point to the same object.


|  x --> [3]   |
| ^|
|   y ||


When I do x = [], a new object is created somewhere else on the page,
and the name x is made to point to the new object. This changes the
arrow. The name "x" is not in any way tied to the location of the [3]
on the page. This doesn't impact "y" which is still pointing at the
same spot it was before


|  x >[] [3]   |
| ^|
|   y ||


That is how Python's object model works. In CPython, objects have
specified memory locations but names do not. In IronPython and Jython,
even that's not guaranteed- the garbage collector can move the objects
around during their lifetime, so while you can trust that a name will
always point to the correct object, you have no guarantee about where
the object is located in the computer's memory.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Benjamin Kaplan
On Jun 14, 2013 9:34 AM, "Michael Torrie"  wrote:
>
> On 06/14/2013 03:50 AM, Nick the Gr33k wrote:
> >  >>> print(name or month or year)
> > abcd
> >  >>> print(name and month and year)
> > ijkl
>
> Interesting.  I'd have thought a boolean expression would return True or
> False, not a string.  Learn something new every day.
>
>
>

Python didn't have a Boolean type for quite some time (2.2?). Until then,
True and False were ints. Since every object had a Boolean value, you
didn't need to turn the result into an integer. In an "and" clause, python
returns the first false value or the last value, because that will evaluate
to the correct Boolean value. In an "or" clause, python returns the first
true value or the last value. When Python finally got a Boolean type, no
one wanted to break backwards compatibility for this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Version Control Software

2013-06-13 Thread Benjamin Kaplan
On Jun 13, 2013 10:17 AM, "Grant Edwards"  wrote:
>
> On 2013-06-13, Ben Finney  wrote:
> > cutems93  writes:
> >
> >> I am looking for an appropriate version control software for python
> >> development, and need professionals' help to make a good decision.
> >
> >> Currently I am considering four software: git, SVN, CVS, and
> >> Mercurial.
> >
> > These days there is no good reason to use CVS nor Subversion for new
> > projects. They are not distributed (the D in DVCS), and they have
> > specific design flaws that often cause insidious problems with common
> > version control workflows. As a salient example, branching and merging
> > are so painful with these tools that many users have learned the
> > terrible habit of never doing it at all.
>
> I agree that branch/merge handling in svn is primitive compared to git
> (haven't used hg enough to comment).
>
> The last time we made the choice (4-5 years ago), Windows support for
> get, bzr, and hg was definitely lacking compared to svn.  The lack of
> something like tortoisesvn for hg/git/bzr was a killer.  It looks like
> the situation has improved since then, but I'd be curious to hear from
> people who do their development on Windows.
>

There's a TortoiseHg now that works well. http://tortoisehg.bitbucket.org

I haven't used it very much, but github has released a git client for
Windows.  The underlying library is the same one Microsoft uses for the
Visual Studio git integration, so I assume it's fairly robust at this point.
http://windows.github.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re-using copyrighted code

2013-06-09 Thread Benjamin Kaplan
On Sun, Jun 9, 2013 at 6:40 PM, Mark Janssen  wrote:
>> Mark, ever watched TV? Or gone to the movies? Or walked into a bookshop?
>> Listened to the radio? All these things publish copyrighted work. It is
>> utter nonsense that merely publishing something in public gives up the
>> monopoly privileges granted by copyright.
>
> That's not correct.  Keep in mind, that the law is for people:  there
> is no automatic right to profit.  There certainly is no "right to
> monopoly" (which you are absurdly arguing) on *anything* released to
> the public.  If you want that monopoly *you* have to provide the means
> to protect your IP.  You, sir, are being ridiculous and perhaps the
> court along with you -- I'm just telling you what is correct.  That's
> important.
>
> A movie producer, publishes his/her work as soon as he/she puts it on
> the market or otherwise releases it for public viewing.  That's just
> the risk of doing business.  Fortunately, for them, its not easy to
> make a verbatim copy of a film, in a theatre or otherwise.   But
> copyright ensures that they get the credit for making the movie -- not
> for profit of publishing it.
>
> Now copyright includes the clause of "fair-use", so that means one can
> make a copy of something if they aren't depriving the original creator
> of legitimate gains.  If they are truly depriving the creator(s) of
> legit gains, then they are in violation.  That's all the law should
> support.  Don't think there is any law that can determine, once and
> for all, what counts as "legitimate gains" and what violates "fair
> use".   *You* have simply *sold out*.   "Legitimate gains" is
> something the courts have to work out, on a case-by-case basis, but if
> the movie producers are that worried about losing their gains, then
> they can do the f-ing work and require movie goers to sign a simple
> clause promising that they won't try to copy the movie (on concealed
> cameras and such).
>



The fact that a work is non commercial is one of several factors that
is taken into account when determining fair use. It is not an
automatic fair use for non-commercial works. I have no idea where your
understanding of copyright law came from, but here is the relevant
section of the US legal code:

17 USC § 107 - Limitations on exclusive rights: Fair use
Notwithstanding the provisions of sections 106 and 106A, the fair use
of a copyrighted work, including such use by reproduction in copies or
phonorecords or by any other means specified by that section, for
purposes such as criticism, comment, news reporting, teaching
(including multiple copies for classroom use), scholarship, or
research, is not an infringement of copyright. In determining whether
the use made of a work in any particular case is a fair use the
factors to be considered shall include—
(1) the purpose and character of the use, including whether such use
is of a commercial nature or is for nonprofit educational purposes;
(2) the nature of the copyrighted work;
(3) the amount and substantiality of the portion used in relation to
the copyrighted work as a whole; and
(4) the effect of the use upon the potential market for or value of
the copyrighted work.
The fact that a work is unpublished shall not itself bar a finding of
fair use if such finding is made upon consideration of all the above
factors.


Can you provide any citations for your interpretation? Besides "that's
what the law should be", I mean.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re-using copyrighted code

2013-06-09 Thread Benjamin Kaplan
On Sun, Jun 9, 2013 at 1:32 PM, Mark Janssen  wrote:
> On Sun, Jun 9, 2013 at 12:50 PM, Michael Torrie  wrote:
>> On 06/09/2013 11:18 AM, Mark Janssen wrote:
>>> You actually do not.  Attaching a legal document is purely a secondary
>>> protection from those who would take away right already granted by US
>>> copyright.
>>
>> You are correct, except that the OP has already stated he wishes to have
>> his code distributed. Without granting a license, the code cannot be
>> distributed beyond the people he personally gives the code too.  PyPi
>> cannot legally allow others to download it without a license.
>
> That's not entirely correct.  If he *publishes* his code (I'm using
> this term "publish" technically to mean "put forth in a way where
> anyone of the general public can or is encouraged to view"), then he
> is *tacitly* giving up protections that secrecy (or *not* disclosing
> it) would *automatically* grant.  The only preserved right is
> authorship after that.   So it can be re-distributed freely, if
> authorship is preserved.  The only issue after that is "fair use" and
> that includes running the program (not merely copying the source).
>

No, the original author retains all rights except those explicitly
granted. The same way that obtaining the "source" to a song does not
give you the right to redistribute the song all you want.

> Re-selling for money violates fair-use, as does redistribution without
> preserving credit assignment (unless they've naively waived those
> rights away).  I will have to take a look at  PyPi.  But if you are
> *publishing*, there's no court which can protect your IP afterwards
> from redistribution, unless you explicitly *restrict* it.  In which
> case, if you restrict terms of re-use, you're putting the court in
> jeopardy because you making two actions opposed to one another.  The
> only thing the court can easily uphold is your authorship and
> non-exploitation from a violation of fair-use (note again the key word
> is "use", nor merely copying the code).  But then if you waive *that*
> right away, you put the court in jeopardy again.
>

Fair use has nothing to do with money. It depends on how the work is
used and how you've changed it. Weird Al's song parodies are fair use,
even though he sells them. You distributing copies of a commercial
software to everyone is not fair use, even though you aren't making
money.

>> Here's how the GPL puts it, and of course this applies to any and all
>> licenses, even proprietary ones:
>>
>> "However, nothing else [besides the License] grants you permission to
>> modify or distribute the Program or its derivative works. These actions
>> are prohibited by law if you do not accept this License. Therefore, by
>> modifying or distributing the Program (or any work based on the
>> Program), you indicate your acceptance of this License to do so, and all
>> its terms and conditions for copying..."
>
> Well this is where one must make a distinction with fair-use -- if I
> re-publish my modifications then the code is still subject to the
> terms by the original author.  If I make a copy for myself and run the
> problem for personal, non-commercial use, then I am in the domain of
> fair use and have no other obligations.
>

Again, no. The GPL does not restrict your rights when running on
machines you control, but that's just because of the terms of the
license. Most commercial licenses include terms like "no reverse
engineering the software" that have nothing to do with distribution.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Benjamin Kaplan
On Sun, Jun 9, 2013 at 2:20 AM, Νικόλαος Κούρας  wrote:
> Τη Κυριακή, 9 Ιουνίου 2013 12:12:36 μ.μ. UTC+3, ο χρήστης Cameron Simpson 
> έγραψε:
>> On 09Jun2013 02:00, =?utf-8?B?zp3Or866zr/PgiDOk866z4EzM866?= 
>>  wrote:
>>
>> | Steven wrote:
>>
>> | >> Since 1 byte can hold up to 256 chars, why not utf-8 use 1-byte for
>>
>> | >> values up to 256?
>>
>> |
>>
>> | >Because then how do you tell when you need one byte, and when you need
>>
>> | >two? If you read two bytes, and see 0x4C 0xFA, does that mean two
>>
>> | >characters, with ordinal values 0x4C and 0xFA, or one character with
>>
>> | >ordinal value 0x4CFA?
>>
>> |
>>
>> | I mean utf-8 could use 1 byte for storing the 1st 256 characters. I meant 
>> up to 256, not above 256.
>>
>>
>>
>> Then it would not be UTF-8. UTF-8 will encode an Unicode codepoint. Your 
>> >suggestion will not.
>
> I dont follow.
>

The point in the UTF formats is that they can encode any of the 1.1
million codepoints available in Unicode. Your suggestion can only
encode 256 code points. We have that encoding already- it's called
Latin-1 and it can't encode any of your Greek characters (hence why
ISO-8859-7 exists, which can encode the Greek characters but not the
Latin ones).

If you were to use the whole byte to store the first 256 characters,
you wouldn't be able to store character number 256 because the
computer wouldn't be able to tell the difference between character 257
(0x01 0x01) and two chr(1)s. UTF-8 gets around this by reserving the
top bit as a "am I part of a multibyte sequence" flag,

>> | >> UTF-8 and UTF-16 and UTF-32
>>
>> | >> I though the number beside of UTF- was to declare how many bits the
>>
>> | >> character set was using to store a character into the hdd, no?
>>
>> |
>>
>> | >Not exactly, but close. UTF-32 is completely 32-bit (4 byte) values.
>>
>> | >UTF-16 mostly uses 16-bit values, but sometimes it combines two 16-bit
>>
>> | >values to make a surrogate pair.
>>
>> |
>>
>> | A surrogate pair is like itting for example Ctrl-A, which means is a 
>> combination character that consists of 2 different characters?
>>
>> | Is this what a surrogate is? a pari of 2 chars?
>>
>>
>>
>> Essentially. The combination represents a code point.
>>
>>
>>
>> | >UTF-8 uses 8-bit values, but sometimes
>>
>> | >it combines two, three or four of them to represent a single code-point.
>>
>> |
>>
>> | 'a' to be utf8 encoded needs 1 byte to be stored ? (since ordinal = 65)
>>
>> | 'α΄' to be utf8 encoded needs 2 bytes to be stored ? (since ordinal is > 
>> 127 )
>>
>> | 'a chinese ideogramm' to be utf8 encoded needs 4 byte to be stored ? 
>> (since ordinal >  65000 )
>>
>> |
>>
>> | The amount of bytes needed to store a character solely depends on the 
>> character's ordinal value in the Unicode table?
>>
>>
>>
>> Essentially. You can read up on the exact process in Wikipedia or the 
>> Unicode Standard.
>
>
>
> When you say essentially means you agree with my statements?
> --

In UTF-8 or UTF-16, the number of bytes required for the character is
dependent on its code point, yes. That isn't the case for UTF-32,
where every character uses exactly four bytes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Benjamin Kaplan
On Sun, Jun 9, 2013 at 2:38 AM, Νικόλαος Κούρας  wrote:
> Τη Κυριακή, 9 Ιουνίου 2013 12:20:58 μ.μ. UTC+3, ο χρήστης Lele Gaifax έγραψε:
>
>> > How about a string i wonder?
>> > s = "νίκος"
>> > what_are these_bytes = s.encode('iso-8869-7').encode(utf-8')
>
>> Ignoring the usual syntax error, this is just a variant of the code I
>> posted: "s.encode('iso-8869-7')" produces a bytes instance which
>> *cannot* be "re-encoded" again in whatever encoding.
>
> s = 'a'
> s = s.encode('iso-8859-7').decode('utf-8')
> print( s )
>
> a (we got the original character back)
> 
> s = 'α'
> s = s.encode('iso-8859-7').decode('utf-8')
> print( s )
>
> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 0: 
> unexpected end of data
>
> Why this error? because 'a' ordinal value > 127 ?
> --

No. You get that error because the string is not encoded in UTF-8.
It's encoded in ISO-8859-7. For ASCII strings (ord(x) < 127),
ISO-8859-7 and UTF-8 look exactly the same. For anything else, they
are different. If you were to try to decode it as ISO-8859-1, it would
succeed, but you would get the character "á" back instead of α.

You're misunderstanding the decode function. Decode doesn't turn it
into a string with the specified encoding. It takes it *from* the
string with the specified encoding and turns it into Python's internal
string representation. In Python 3.3, that encoding doesn't even have
a name because it's not a standard encoding. So you want the decode
argument to match the encode argument.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re-using copyrighted code

2013-06-08 Thread Benjamin Kaplan
On Sat, Jun 8, 2013 at 2:31 PM, Malte Forkel  wrote:
> Hello,
>
> I have written a small utility to locate errors in regular expressions
> that I want to upload to PyPI.  Before I do that, I would like to learn
> a litte more about the legal aspects of open-source software. What would
> be a good introductory reading?
>
> Plus, I have one very specific question: In my package, I use modified
> code from sre_parse.py, which is part of the Python release. That file
> has the following header:
>
> #
> # Secret Labs' Regular Expression Engine
> #
> # convert re-style regular expression to sre pattern
> #
> # Copyright (c) 1998-2001 by Secret Labs AB.  All rights reserved.
> #
> # See the sre.py file for information on usage and redistribution.
> #
>
> The referenced information is missing in the version of sre.py that
> comes with current versions of Python, but I found it in the archive
> http://effbot.org/media/downloads/sre-2.2.1.zip. It reads:
>
> #
> # Secret Labs' Regular Expression Engine
> #
> # re-compatible interface for the sre matching engine
> #
> # Copyright (c) 1998-2001 by Secret Labs AB.  All rights reserved.
> #
> # This version of the SRE library can be redistributed under CNRI's
> # Python 1.6 license.  For any other use, please contact Secret Labs
> # AB (i...@pythonware.com).
> #
> # Portions of this engine have been developed in cooperation with
> # CNRI.  Hewlett-Packard provided funding for 1.6 integration and
> # other compatibility work.
> #
>
> Now, how am I supposed to deal with that? Ask Secret Labs for some kind
> of permission? Leave it as it is and add my own copyright line?
>
> Malte
>

You can find the license terms for all versions of Python at
http://docs.python.org/3/license.html
I'm not a lawyer, but it looks like you just need to include the
copyright statement.

I'm not sure why the sre stuff is still licensed under the 1.6
license. Did no one get permission to distribute it under the PSF
license, or did no one bother to rewrite the comment in the file?
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python #ifdef

2013-05-28 Thread Benjamin Kaplan
On May 28, 2013 1:10 PM, "Carlos Nepomuceno" 
wrote:
>
> Thank you! I made it run like the following. What do you think about
that? IS there a better way?
>
>
>
> #The following runs on Python 2.7
> sc3='''
> # Python 3
> def original(n):
> m = 0
> for b in n.to_bytes(6, 'big'):
> m = 256*m + b
> return m
> '''
> if sys.version_info[0] == 3:
> exec(sc3)
> --

No need for exec.

if sys.version_info[0] >= 3:
def original(n) :
   ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: in need of some help regarding my rock paper scissors game

2013-05-12 Thread Benjamin Kaplan
On Sun, May 12, 2013 at 12:33 PM, Alex Norton  wrote:
> im new to python and im in the middle of making a RPS game for a college
> unit.
>
> i have used PyQt to create the GUI and i have received help regarding adding
> the code to the buttons.
>
> but its missing something as the error
>
> 'Traceback (most recent call last): File "C:\Users\Me\Desktop\testy.py",
> line 174, in bWater.clicked.connect( water_clicked ) AttributeError: 'int'
> object has no attribute 'clicked'' appears when i run the module.
>
> i was wondering if somebody could walk me through making the game complete
> and to add the results of the game (win/lose/stalemate) to the loutcome
> label
>
>  attached is the game file.
>
> --

bWater is an int. Integers don't have a clicked attribute. So
bWater.clicked.connect(water_clicked) looks for the clicked attribute
of the integer bWater, can't find it, and throws an error. Also,
Python scripts are executed line by line- at the time you make that
call, the water_clicked function doesn't exist yet, so even if that
was the correct call, it wouldn't work here.

I haven't used PyQT before so I can't say what the correct way to set
this up would be, but that's at least what's causing this error.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why do Perl programmers make more money than Python programmers

2013-05-07 Thread Benjamin Kaplan
On May 7, 2013 5:42 PM, "Neil Hodgson"  wrote:
>
> jmfauth:
>
>> 2) More critical, Py 3.3, just becomes non unicode compliant,
>> (eg European languages or "ascii" typographers !)
>> ...
>
>
>This is not demonstrating non-compliance. It is comparing performance,
not compliance.
>
>Please show an example where Python 3.3 is not compliant with Unicode.
>
>Neil
> --
> http://mail.python.org/mailman/listinfo/python-list

It's violating page 1+1j of the Unicode spec, where it says precisely how
long each operation is allowed to take. Only wise people can see that page.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Unicode support so hard...

2013-04-20 Thread Benjamin Kaplan
On Sat, Apr 20, 2013 at 10:22 AM, Ned Batchelder  wrote:
> On 4/20/2013 1:12 PM, jmfauth wrote:
>>
>> In a previous post,
>>
>>
>> http://groups.google.com/group/comp.lang.python/browse_thread/thread/6aec70817705c226#
>> ,
>>
>> Chris “Kwpolska” Warrick wrote:
>>
>> “Is Unicode support so hard, especially in the 21st century?”
>>
>> --
>>
>> Unicode is not really complicate and it works very well (more
>> than two decades of development if you take into account
>> iso-14).
>>
>> But, - I can say, "as usual" - people prefer to spend their
>> time to make a "better Unicode than Unicode" and it usually
>> fails. Python does not escape to this rule.
>>
>> -
>>
>> I'm "busy" with TeX (unicode engine variant), fonts and typography.
>> This gives me plenty of ideas to test the "flexible string
>> representation" (FSR). I should recognize this FSR is failing
>> particulary very well...
>>
>> I can almost say, a delight.
>>
>> jmf
>> Unicode lover
>
> I'm totally confused about what you are saying.  What does "make a better
> Unicode than Unicode" mean?  Are you saying that Python is guilty of this?
> In what way?  Can you provide specifics?  Or are you saying that you like
> how Python has implemented it?  "FSR is failing ... a delight"?  I don't
> know what you mean.
>
> --Ned.

Don't bother trying to figure this out. jmfauth has been hijacking
every thread that mentions Unicode to complain about the flexible
string representation introduced in Python 3.3. Apparently, having
proper Unicode semantics (indexing is based on characters, not code
points) at the expense of performance when calling .replace on the
only non-ASCII or BMP character in the string is a horrible bug.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe and 64/32 bit windows

2013-04-09 Thread Benjamin Kaplan
On Apr 9, 2013 12:53 PM, "Grant Edwards"  wrote:
>
> On 2013-04-09, Ian Kelly  wrote:
>
> >> My "Windows partition" currently has a 64-bit Windows 7 Ultimate
> >> installation.
> >>
> >> I'm told that the executable I generate on that machine won't run on
> >> Win7 32-bit installations.  I'm not surprised by that, but I'd like
> >> to provide 32-bit operability -- and I'm not sure how one does that.
> >>
> >>  * If I built an executable on a 32-bit windows system using py2exe,
> >>would it be usable on a 64-bit install?
> >
> > Yes, 64-bit Windows systems will run 32-bit executables.
>
> OK, that's good to know.
>
> >>  * Is there such a thing as a "fat" Windows binary that will run on
> >>both 32 and 64 bit systems?
> >
> > With .NET applications you can choose an AnyCPU build target that
> > will dynamically select 32-bit or 64-bit at runtime based on the host
> > OS, but there is no such feature for native applications like
> > CPython.
> >
> >>  * Or do you build separate 32 and 64 bit binaries and rely on the
> >>installer to pick the right files?  [If Inno Setup can't do that, I
> >>can probably get somebody else to build the installer using
> >>something that can.]
> >
> > You could do that.  The easiest thing to do though is just to make
> > sure that your 64-bit Windows installation is using a 32-bit Python
> > installation.  py2exe doesn't really build anything; it just bundles
> > your source files up with the Python interpreter, so as long as that
> > interpreter is 32-bit the generated exes should be able to run on
> > either platform.
>
> Cool, I'll try that.
>
> Are there any drawbacks to running a 32-bit Python install on a 64-bit
> machine?
>
> Can you have both 32 and 64 bit Python installed at the same time?
>
> --
> Grant Edwards   grant.b.edwardsYow! Is it clean in
other
>   at   dimensions?
>   gmail.com
> --

There aren't any drawbacks besides the usual 32-bit limitations (the memory
limit and you can't load 64-bit libs from a 32-bit exe). You can run both
32-bit and 64-bit python side by side.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to do a Lispy-esque read?

2013-04-08 Thread Benjamin Kaplan
There is no "read in a stream until it's a valid literal" function as
far as I know, but ast.literal_eval will turn your string into an
object.

On Mon, Apr 8, 2013 at 12:45 AM,   wrote:
> Suppose I want to read an object from some stream. How do I do it?
>
> For example, if the input stream contained the text:
> [1, # python should ignore this comment
> 2]
>
> and I do a "read" on it, I should obtain the result
> [1, 2]
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I hate you all

2013-04-05 Thread Benjamin Kaplan
On Fri, Apr 5, 2013 at 10:07 PM, Timothy Madden  wrote:
>
> On 06.04.2013 03:35, Chris Angelico wrote:
>>
>> On Sat, Apr 6, 2013 at 11:22 AM,   wrote:
>>>
>>> On Saturday, April 6, 2013 1:42:15 AM UTC+3, Ian wrote:
>>> [...]

 The "def" line has four spaces.  The "for" line then has a hard tab.
 This is ambiguous.  If the hard tab is assumed to have a width of four
 spaces, then they are at the same indentation level.  If it is assumed
 to have a width of eight spaces, then they are not.
>>>
>>> [...]
>>>
>>> The correct tab stop positions have always been at 8 character columns 
>>> apart.
>>> The "ambiguity" was introduced by editors that do not follow the default 
>>> value set in hardware like printers or used by consoles and terminal 
>>> emulators.
>>>
>>> And now python forces me out of using any tab characters at all. I believe 
>>> I should still have a choice, python should at lest give an option to set 
>>> tab size, if the default of 8 is ambiguous now.
>>
>>
>> If you're indenting four spaces per level, then indent four spaces per
>> level. The code you posted would work perfectly if the indentation is
>> four spaces, then eight spaces, then twelve spaces. The problem is
>> that you have a stupid editor that's enforcing tabs instead of certain
>> multiples of spaces - get one that'll keep them all as spaces and you
>> won't have a problem.
>
>
> My editor is not the problem, of course, this is about what I think is right. 
> I think I should be given the option to use tabs as I always have, and at 
> least to use them with the default tab size, as python 2 used to.
>
>
>> Or use actual tabs, and set the displayed tab width to whatever you
>> feel like. That works, too. Neither option causes any problems with
>> any sane tools.
>
>
> Well this is the problem, the tab size is not "whatever I like", tab stops 
> are 8 character columns apart (default).
>
> Changing the tab size from this default is what makes the code incompatible, 
> not the tabs themselves. So the solution is simple: do not change tab size 
> from the default.
>
> People say I can use tabs all the way, just set them to the indent I want.
>
> Well, I always had my indent independent of the tab size. Which is the way it 
> should be, after all, since one can indent with or without tabs, so indent 
> should not be tied to them.
>
> But now I can not; python no longer lets me do that.
>
> Tab size should be 8, so now python 3 says: either indent at 8 with tabs, 
> either drop tabs and indent with spaces (just the same as if tabs are not 
> allowed).
>
> But that is so wrong. I can indent at 4 (or any value), and still use tabs, 
> as long as the interpreter knows tab stops are 8 columns apart. There is no 
> "ambiguity" and no way to change the meaning of the code.
>
> So as a comparison we have:
>
>  - the good old rules
> - python has use the default tab stops of 8 columns
> - indent is independent of tab stops
>
>  - the new rules
> - python is independent of the tab stops
> - indent is now tied to the tab stop, so users have to :
> - use non-default tab size (8 is too much), or
> - drop tabs altogether
>
> The new rules may look flexible at first sight, but the net effect they have 
> is they push me to use non-default tab size (which is not good), or drop the 
> tabs, which I could have used before python 3 just fine.
>
>
> Thank you,
> Timothy Madden

http://www.xkcd.com/1172/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python class and variable issue(newby question!)

2013-03-29 Thread Benjamin Kaplan
On Fri, Mar 29, 2013 at 2:12 PM, Sam Berry  wrote:
> Hey,
>
> Im new to object orientated programming and have an issue with using classes. 
> Im using the kivy module, a GUI creator , so posting the actual code may 
> confuse. But an example of what im trying to achieve is below
>
> class test()
> s = 1
>
> def test1()
> global s
> s = 2
>
> def test2()
> global s
> s = 3
>
> def test3()
> global s
> s = 4
>
>
> class test4()
>
> def printing()
> print test().s
>
> After been in the test()class  a choice of buttons allows the user to run 
> either of the functions within it and sends us into the test4() class. Then 
> another button runs printing().
>
> However printing() always prints 1, even if the variable has been changed. Im 
> guessing because  print test().s  redefines the variable. May be a very 
> simple to solve problem, but i cant figure it out.
>
> Any insights of how to get this working, or example code would be very 
> helpful!
>
> Thanks, Sam
> --


There are three different namespaces here: global, class, and local.
You're assigning to the global s, which exists outside the class. Do
"print s" instead of "print test().s" and you'll see your changed
value of s. If you want to change the value of s inside the class,
it's called "test.s" (notice that there's no parenthesis- that's
because s here is an attribute of the test class, not each instance of
test. The same value will be shared by all instances of that class).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]

2013-03-28 Thread Benjamin Kaplan
On Thu, Mar 28, 2013 at 2:11 PM, jmfauth  wrote:
> On 28 mar, 21:29, Benjamin Kaplan  wrote:
>> On Thu, Mar 28, 2013 at 10:48 AM, jmfauth  wrote:
>> > On 28 mar, 17:33, Ian Kelly  wrote:
>> >> On Thu, Mar 28, 2013 at 7:34 AM, jmfauth  wrote:
>> >> > The flexible string representation takes the problem from the
>> >> > other side, it attempts to work with the characters by using
>> >> > their representations and it (can only) fails...
>>
>> >> This is false.  As I've pointed out to you before, the FSR does not
>> >> divide characters up by representation.  It divides them up by
>> >> codepoint -- more specifically, by the *bit-width* of the codepoint.
>> >> We call the internal format of the string "ASCII" or "Latin-1" or
>> >> "UCS-2" for conciseness and a point of reference, but fundamentally
>> >> all of the FSR formats are simply byte arrays of *codepoints* -- you
>> >> know, those things you keep harping on.  The major optimization
>> >> performed by the FSR is to consistently truncate the leading zero
>> >> bytes from each codepoint when it is possible to do so safely.  But
>> >> regardless of to what extent this truncation is applied, the string is
>> >> *always* internally just an array of codepoints, and the same
>> >> algorithms apply for all representations.
>>
>> > -
>>
>> > You know, we can discuss this ad nauseam. What is important
>> > is Unicode.
>>
>> > You have transformed Python back in an ascii oriented product.
>>
>> > If Python had imlemented Unicode correctly, there would
>> > be no difference in using an "a", "é", "€" or any character,
>> > what the narrow builds did.
>>
>> > If I am practically the only one, who speakes /discusses about
>> > this, I can ensure you, this has been noticed.
>>
>> > Now, it's time to prepare the Asparagus, the "jambon cru"
>> > and a good bottle a dry white wine.
>>
>> > jmf
>>
>> You still have yet to explain how Python's string representation is
>> wrong. Just how it isn't optimal for one specific case. Here's how I
>> understand it:
>>
>> 1) Strings are sequences of stuff. Generally, we talk about strings as
>> either sequences of bytes or sequences of characters.
>>
>> 2) Unicode is a format used to represent characters. Therefore,
>> Unicode strings are character strings, not byte strings.
>>
>> 2) Encodings  are functions that map characters to bytes. They
>> typically also define an inverse function that converts from bytes
>> back to characters.
>>
>> 3) UTF-8 IS NOT UNICODE. It is an encoding- one of those functions I
>> mentioned in the previous point. It happens to be one of the five
>> standard encodings that is defined for all characters in the Unicode
>> standard (the others being the little and big endian variants of
>> UTF-16 and UTF-32).
>>
>> 4) The internal representation of a character string DOES NOT MATTER.
>> All that matters is that the API represents it as a string of
>> characters, regardless of the representation. We could implement
>> character strings by putting the Unicode code-points in binary-coded
>> decimal and it would be a Unicode character string.
>>
>> 5) The String type that .NET and Java (and unicode type in Python
>> narrow builds) use is not a character string. It is a string of
>> shorts, each of which corresponds to a UTF-16 code point. I know this
>> is the case because in all of these, the length of "\u1f435" is 2 even
>> though it only consists of one character.
>>
>> 6) The new string representation in Python 3.3 can successfully
>> represent all characters in the Unicode standard. The actual number of
>> bytes that each character consumes is invisible to the user.
>
> --
>
>
> I shew enough examples. As soon as you are using non latin-1 chars
> your "optimization" just became irrelevant and not only this, you
> are penalized.
>
> I'm sorry, saying Python now is just covering the whole unicode
> range is not a valuable excuse. I prefer a "correct" version with
> a narrower range of chars, especially if this range represents
> the "daily used chars".
>
> I can go a step further, if I wish to write an application for
> Western European users, I'm better served if I'm using a coding
> scheme covering all thesee languages/scripts. What about cp1252 [*]?
> Does this not remind somthing?
>
> Python can do better, it only succeeds to do worth!
>
> [*] yes, I kwnow, internally 
>
> jmf

By that logic, we should all be using ASCII because it's "correct" for
the 127 characters that I (as an English speaker) use, and therefore
it's all that we should care about. I don't care if é counts as two
characters, it's faster and more memory efficient for all of my
strings to just count bytes. There are certain domains where
characters outside the basic multilingual plane are used. Python's job
is to be correct in all of those circumstances, not just the ones you
care about.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]

2013-03-28 Thread Benjamin Kaplan
On Thu, Mar 28, 2013 at 10:48 AM, jmfauth  wrote:
> On 28 mar, 17:33, Ian Kelly  wrote:
>> On Thu, Mar 28, 2013 at 7:34 AM, jmfauth  wrote:
>> > The flexible string representation takes the problem from the
>> > other side, it attempts to work with the characters by using
>> > their representations and it (can only) fails...
>>
>> This is false.  As I've pointed out to you before, the FSR does not
>> divide characters up by representation.  It divides them up by
>> codepoint -- more specifically, by the *bit-width* of the codepoint.
>> We call the internal format of the string "ASCII" or "Latin-1" or
>> "UCS-2" for conciseness and a point of reference, but fundamentally
>> all of the FSR formats are simply byte arrays of *codepoints* -- you
>> know, those things you keep harping on.  The major optimization
>> performed by the FSR is to consistently truncate the leading zero
>> bytes from each codepoint when it is possible to do so safely.  But
>> regardless of to what extent this truncation is applied, the string is
>> *always* internally just an array of codepoints, and the same
>> algorithms apply for all representations.
>
> -
>
> You know, we can discuss this ad nauseam. What is important
> is Unicode.
>
> You have transformed Python back in an ascii oriented product.
>
> If Python had imlemented Unicode correctly, there would
> be no difference in using an "a", "é", "€" or any character,
> what the narrow builds did.
>
> If I am practically the only one, who speakes /discusses about
> this, I can ensure you, this has been noticed.
>
> Now, it's time to prepare the Asparagus, the "jambon cru"
> and a good bottle a dry white wine.
>
> jmf
>
>
You still have yet to explain how Python's string representation is
wrong. Just how it isn't optimal for one specific case. Here's how I
understand it:

1) Strings are sequences of stuff. Generally, we talk about strings as
either sequences of bytes or sequences of characters.

2) Unicode is a format used to represent characters. Therefore,
Unicode strings are character strings, not byte strings.

2) Encodings  are functions that map characters to bytes. They
typically also define an inverse function that converts from bytes
back to characters.

3) UTF-8 IS NOT UNICODE. It is an encoding- one of those functions I
mentioned in the previous point. It happens to be one of the five
standard encodings that is defined for all characters in the Unicode
standard (the others being the little and big endian variants of
UTF-16 and UTF-32).

4) The internal representation of a character string DOES NOT MATTER.
All that matters is that the API represents it as a string of
characters, regardless of the representation. We could implement
character strings by putting the Unicode code-points in binary-coded
decimal and it would be a Unicode character string.

5) The String type that .NET and Java (and unicode type in Python
narrow builds) use is not a character string. It is a string of
shorts, each of which corresponds to a UTF-16 code point. I know this
is the case because in all of these, the length of "\u1f435" is 2 even
though it only consists of one character.

6) The new string representation in Python 3.3 can successfully
represent all characters in the Unicode standard. The actual number of
bytes that each character consumes is invisible to the user.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] Message passing syntax for objects

2013-03-18 Thread Benjamin Kaplan
On Mon, Mar 18, 2013 at 1:24 PM, Mark Janssen  wrote:
> On Mon, Mar 18, 2013 at 12:06 PM, Georg Brandl  wrote:
>> Am 18.03.2013 05:26, schrieb Mark Janssen:
>>> Continuing on this thread, there would be a new bunch of behaviors to
>>> be defined.  Since "everything is an object", there can now be a
>>> standard way to define the *next* common abstraction of "every object
>>> interacts with other objects".
>>
>> The problem is that for most objects there isn't *the* interaction.  Sure,
>> you could split up complicated objects into small pieces with a smaller
>> functionality, but at some point you have to stop.
>
> Yes.  But that is the point, if you look at the quora post -- to
> invert the object model and create mashups of simple modular data
> types and working *upwards*.
>
>>  Let's see how this
>> concept fares with simple types such as integers or collections...
>>
>> 42 >> MyNumberType #would add the integer to your integer type
>>
>> That's just random.  Why not multiply?  Why not exponentiate?
>
> Well, as I noted in another post, that while these can be broken down
> into their simpler component (addition and negative numbers), numbers
> should probably be treated separately.
>
>> 42 >> MyCollectionType  #would add the object into your collection:
>>>  *poof*: no more random syntaxiis for putting things in collections.\
>>
>> So you've replaced one method of a collections API by your magical operator,
>> for all collections.
>
> Yes -- for all collections.  That's a pretty big gain right?
>

Nope. No gain at all. Instead of learning the add() method, you learn
the >> operator. You have not simplified anything.
>> It seems that you are reinventing pipes (such as UNIX shell pipes).
>
> That is a very interesting comparison.  That is something like what
> I'm trying to do.  In tandem with the Internet, I do see a kind of
> synthesis of Web + O.S. integration -- ultimately, creating a "data
> ecosystem".
>
> mark

Yes, having the whole program run by chaining functions together is a
neat idea. And it works great in functional languages- if you want
that as a feature, use OCaml or Haskell. It works less well in
imperative languages where you are manipulating data, not just passing
it around.

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


Re: [Python-ideas] Message passing syntax for objects

2013-03-18 Thread Benjamin Kaplan
On Mon, Mar 18, 2013 at 10:18 AM, Mark Janssen
 wrote:
>> Ian Cordasco wrote:
>>>
>>> On Sun, Mar 17, 2013 at 11:53 PM, Mark Janssen
>>>  wrote:
>>>
 Hello,

 I just posted an answers on quora.com about OOP (http://qr.ae/TM1Vb)
 and wanted to engage the python community on the subject.
>>
>>
>> My answer to that question would be that it *did*
>> catch on, it's just that we changed the terminology.
>> Instead of message passing, we talk about calling
>> methods.
>
> Yes, but this is where it breaks the OOP abstraction by 90 degrees.
> By using function calls, you're telling the machine to do something.
> But when you want to pass something to an object there should be a
> natural way to do this for every object.  By using methods you pollute
> the concept space with all sorts of semi-random (i.e. personal) names,
> like append, add, enqueue, etc.
>
> This proposal would not only make a consistent syntax across all
> objects, but train the programmer to *think* modularly in the sense of
> having a community of re-usable object.  I.e. "What should I do if
> another object passes me something?".  No one thinks this now, because
> the programmer expects new developers to learn *their* interface!
>
> Mark
> --

You're dreaming of a utopia where computers just read our minds and
know what we're thinking. So what if I can pass 42 into an object.
What do I intend to happen with that 42? Do I want to add the element
to a list? Access the 42nd element? Delete the 42nd element? Let the
object pick a behavior at random? Clearly there must be some sort of
behavior defined for passing a message into an object. And now we're
back to learning the interface that the programmer designed. Only now,
instead of having different types of behavior grouped together into
classes, we have to use a different object for each operation. So
what's the benefit of that over having the object implement the
__call__ method?

Also, why would we re-use the bit shift operators for message passing?
Just because C++ decided to overload the existing operators to mean
reading into and writing out of a stream doesn't mean it's a good
idea.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyWart: NameError trackbacks are superfluous

2013-03-16 Thread Benjamin Kaplan
On Sat, Mar 16, 2013 at 8:14 PM, Steven D'Aprano
 wrote:
> On Sat, 16 Mar 2013 19:58:41 -0600, Michael Torrie wrote:
>
>> On 03/16/2013 06:11 PM, Rick Johnson wrote:
>>> No, the "ACTUAL PROBLEM" is in the author.
>>
>> Surely any NameException can also be blamed on the author then, by your
>> logic?
>
> Any exception at all is obviously the author's fault. I propose that
> Python stops wasting our time with debugging information and tracebacks,
> and on any error, simply prints the following message then dump core:
>
>
> PEBKACError: Programmer is an idiot. You did something wrong, you moron,
> turn your computer off, you're obviously too stupid to program.
>
>
> That will certainly improve productivity.
>
> --
> Steven

Don't have it dump core. Have it print a pink slip to the default printer.
-- 
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-03-04 Thread Benjamin Kaplan
On Mar 4, 2013 3:02 PM, "CM"  wrote:
>
>
> > The main issue is that python has dynamic typing.  The type of object
> > that is referenced by a particular name can vary, and there's no way
> > (in general) to know at compile time what the type of object "foo" is.
> >
> > That makes generating object code to manipulate "foo" very difficult.
>
> Could you help me understand this better?  For example, if you
> have this line in the Python program:
>
> foo = 'some text'
> bar = {'apple':'fruit'}
>
> If the interpreter can determine at runtime that foo is a string
> and bar is a dict, why can't the compiler figure that out at
> compile time?  Or is the problem that if later in the program
> you have this line:
>
> foo = 12
>
> now foo is referring to an integer object, not a string, and
> compilers can't have two names referring to two different
> types of objects?  Something like that?
>
> I in no way doubt you that this is not possible, I just don't
> understand enough about how compiling works to yet "get"
> why dynamic typing is a problem for compilers.
>
> Thanks.
> --
> http://mail.python.org/mailman/listinfo/python-list

In the case of literals, the compiler can figure out type information (and
I believe it does do some constant folding). But as soon as you let
something else get in between you and the constant, you lose all guarantees.

import random

if random.random() <0.5 :
spam = 3
else:
spam = "hello world"

Then you get into monkey patching and dealing with types that may not be
defined at compile time. The only way a python compiler could convert that
to x86 assembly is if generated code that would look up the type
information at runtime. You'd basically be outputting a python interpreter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to install development package on linux?

2013-03-02 Thread Benjamin Kaplan
On Sat, Mar 2, 2013 at 10:14 PM, Sarbjit singh  wrote:
>
> I searched on google and found these errors could be due to missing python 
> header files which would be available in development package.
>
> So I am struggling to make it work.


A "development package" is meaningless when you aren't installing it
from a package. Debian's binary packages don't include the header
files, so they put them in a different package. Since you compiled
from source, you already have the header files. Did you include the
directory you installed Python into on your library and includes
paths?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: In win32 and linux platform, os modules has diffreent output order, is it a bug?

2013-03-01 Thread Benjamin Kaplan
On Fri, Mar 1, 2013 at 12:43 AM, Honghe Wu  wrote:
> env: python 2.7.3
>
> 6 test files' name in a directory as below:
> 12ab  Abc  Eab  a1bc  acd  bc
>
> the following is test code:
> for root, dirs, files in os.walk(os.getcwd()):
> print files
>
> the output in win32 platform is:
> ['12ab', 'a1bc', 'Abc', 'acd', 'bc', 'Eab']
>
> but in linux is:
> ['Eab', 'acd', 'a1bc', '12ab', 'bc', 'Abc' ]
>
> they are so different. a bug?
> --

The function doesn't specify a particular order, just that it will
hand you a list of files. It grabs those from the underlying file
system. It looks like Windows sorts it alphabetically and Linux just
does whatever (maybe sorted by creation time?). I don't think it's a
bug. If the order matters to you, sort it yourself.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cymbalic reference?

2013-01-15 Thread Benjamin Kaplan
On Tue, Jan 15, 2013 at 8:56 PM, rh  wrote:
> I have this working and I am curious to know how others do same.
>
> class Abc(object):
> def __init__(self):
> pass
> def good(self):
> print "Abc good"
> def better(self):
> print "Abc better"
>
> urls = {'Abc':'http://example.com'}
> strings = ['good', 'better']
>
> for s in urls:
> o = eval("%s()" % s)
> for string in strings:
> eval("o.%s()" % string)
>
>
> Yes, 'spose symbolic references is what these are
>
> While I'm at it what magic could I use to print "the-class-I-am-in good"
> instead of hard-coding "Abc good"? I tried __class_ and self.__class__
>
> --

Rather than using eval, you can grab the class out of globals(), and
then use getattr to get the methods.

>>> for s in urls :
... o = globals()[s]()
... for method in strings :
... getattr(o, method)()
...
Abc good
Abc better

And for getting the class name, the class has a __name__ attribute. So
you could use self.__class__.__name__.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wiki.python.org

2013-01-09 Thread Benjamin Kaplan
On Wed, Jan 9, 2013 at 8:30 AM, Ken  wrote:
> On Wed, Jan 09, 2013 at 04:05:31PM +, Reed, Kevin wrote:
>> Hello,
>>
>> I have been unable to access wiki.python.org for two days.  Is there a 
>> problem with the server, or is it me?
>>
>> Thank you much,
>>
>> Kevin C. Reed
>> New Python User
>
> Well, I just tried it twice and could not get there, so I would say it
> is a problem on the server's end.
>
> Ken
>
>

The server was compromised with a zero-day remote code exploit. It was
taken offline to prevent further damage.

http://mail.python.org/pipermail/python-list/2013-January/638182.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do you call a function several times in this context??

2013-01-06 Thread Benjamin Kaplan
On Jan 6, 2013 12:33 PM, "kofi"  wrote:
>
> Using python 3.1, I have written a function called "isEvenDigit"
>
> Below is the code for the "isEvenDigit" function:
>
> def isEvenDigit():
> ste=input("Please input a single character string: ")
> li=["0","2","4", "6", "8"]
> if ste in li:
> print("True")
> else:
> print("False")
>
> I am now trying to write a function that takes a string as an argument
and makes several calls to the isEvenDigit function in order to calculate
and return the number of even digits in the string.How do i do this please?
This is what i have done so far.
>
> def isEvenDigit2():
> number = input("Enter a digit: ")

Use a loop and call the function in the body of the loop. In this case, you
would use a for loop iterating over number. If you don't know how to use a
for loop, I recommend you do the tutorial at
http://docs.python.org/3.3/tutorial/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 3.2 can't extract tarfile produced by 2.7

2012-12-26 Thread Benjamin Kaplan
On Dec 26, 2012 11:00 AM, "Antoon Pardon" 
wrote:
>
> I am converting some programs to python 3. These programs manipulate
tarfiles. In order for the python3 programs to be really useful
> they need to be able to process the tarfiles produced by python2 that
however seems to be a problem.
>
> This is testcode that produces a tarfile.
>
> #! /usr/bin/python
>
> compression = "bz2"
> tarmode = "w|%s" % compression
> rt = '.'
>
> import os
> import os.path
> import errno
>
> import tarfile as tar
>
> def process():
> pj = os.path.join
> entries = os.listdir(rt)
> of = open("DUMP.tbz", "w")
> tf = tar.open(mode = tarmode, fileobj = of,
>   encoding = 'ascii', format = tar.PAX_FORMAT)
> for entry in entries:
> fqpn = pj(rt, entry)
> try:
> tf.add(fqpn, entry, recursive = False)
> except OSError as ErrInfo:
> print("%s: disappeared" % fqpn)
> if ErrInfo.errno != errno.ENOENT:
> raise
> tf.close()
> of.close()
>
> if __name__ == "__main__":
> process()
>
>
==
> This is testcode that checks a tarfile
>
> #!/usr/bin/python
>
> compression = "bz2"
> tarmode = "r|%s" % compression
>
> import os
> import os.path
> import stat
>
> import tarfile as tar
>
> def equalfile(fl1, fl2):
> bf1 = fl1.read(8192)
> bf2 = fl2.read(8192)
> while bf1 == bf2:
> if bf1 == "":
> return True
> bf1 = fl1.read(8192)
> bf2 = fl2.read(8192)
> return False
>
> def process():
> gf = open("DUMP.tbz", "r")
> tf = tar.open(mode = tarmode, fileobj = gf,
>   encoding = 'ascii', format = tar.PAX_FORMAT)
> for tarinfo in tf:
> entry = tarinfo.name
> fileinfo = os.stat(entry)
> if stat.S_ISREG(fileinfo.st_mode) and tarinfo.isreg():
> bfl = tf.extractfile(tarinfo)
> ofl = open(entry)
> if not equalfile(bfl, ofl):
> print("%s: does not match backup" % entry)
> sync = False
> tf.close()
> gf.close()
>
> if __name__ == "__main__":
> process()
>
>
=
>
> When I use python2.7 to produce and later check the tarfile everything
works as expected. However when I use python3.2 to check the tarfile I
> get the following traceback.
>
> Traceback (most recent call last):
>   File "tarchck", line 39, in 
> process()
>   File "tarchck", line 25, in process
> encoding = 'ascii', format = tar.PAX_FORMAT)
>   File "/usr/lib/python3.2/tarfile.py", line 1771, in open
> t = cls(name, filemode, stream, **kwargs)
>   File "/usr/lib/python3.2/tarfile.py", line 1667, in __init__
> self.firstmember = self.next()
>   File "/usr/lib/python3.2/tarfile.py", line 2418, in next
> tarinfo = self.tarinfo.fromtarfile(self)
>   File "/usr/lib/python3.2/tarfile.py", line 1281, in fromtarfile
> buf = tarfile.fileobj.read(BLOCKSIZE)
>   File "/usr/lib/python3.2/tarfile.py", line 573, in read
> buf = self._read(size)
>   File "/usr/lib/python3.2/tarfile.py", line 585, in _read
> buf = self.__read(self.bufsize)
>   File "/usr/lib/python3.2/tarfile.py", line 604, in __read
> buf = self.fileobj.read(self.bufsize)
>   File "/usr/lib/python3.2/codecs.py", line 300, in decode
> (result, consumed) = self._buffer_decode(data, self.errors, final)
> UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9e in position 10:
invalid start byte
>
> I have been looking around but have no idea how I have to adapt this code
in order to have it process the tarfile under python3.2. The original code
didn't have the coding and format keywords on the tar.open statement and
after reading the documentation I thought that
> would make things work, but no such luck. Further reading didn't
> provide anything usefull
>
> --
> Antoon Pardon
> --

You're opening the file in text mode, so it's trying to decode it as text
using your default encoding (utf-8). You want the file read as a series of
bytes, so open it in binary mode.

gf =open("DUMP.tbz", "rb")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compile python 3.3 with bz2 support

2012-12-22 Thread Benjamin Kaplan
On Dec 21, 2012 1:31 AM, "Isml" <76069...@qq.com> wrote:
>
> hi, everyone:
> I want to compile python 3.3 with bz2 support on RedHat 5.5 but fail
to do that. Here is how I do it:
> 1. download bzip2 and compile it(make、make -f Makefile_libbz2_so、make
install)
> 2.chang to python 3.3 source directory : ./configure
--with-bz2=/usr/local/include
> 3. make
> 4. make install
>
> after installation complete, I test it:
> [root@localhost Python-3.3.0]# python3 -c "import bz2"
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/local/lib/python3.3/bz2.py", line 21, in 
> from _bz2 import BZ2Compressor, BZ2Decompressor
> ImportError: No module named '_bz2'
> By the way, RedHat 5.5 has a built-in python 2.4.3. Would it be a problem?
>
>
> --

What is the output of configure? The last thing it does is list which
modules are not going to be built. Is bz2 on the list? What does configure
say when it's looking for bz2?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode

2012-12-17 Thread Benjamin Kaplan
On Mon, Dec 17, 2012 at 12:59 AM, Anatoli Hristov  wrote:
>> What happens when you do use UTF-8?
> This is the result when I encode the string:
> " étroits, en utilisant un portable extrêmement puissant—le plus
> petit et le plus léger des HP EliteBook pleine puissance—avec un
> écran de diagonale 31,75 cm (12,5 pouces), idéal pour le
> professionnel ultra-mobile.
> "
> No accents
>>
>> What do you mean, "use UTF-8"?
>
> Trying to encode the string
>>

What's your terminal's encoding? That looks like you have a CP-1252
terminal trying to output UTF-8 text.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re:

2012-12-15 Thread Benjamin Kaplan
On Sat, Dec 15, 2012 at 5:49 PM, Dustin Guerri  wrote:
>
> Hi there,
>
> I'm new to Python and to programming.  is this the right place for me to
> post a beginner question on Python use ?
>
> Many thanks.
>

You could post questions here, but it would be better to use the
Python-tutor list for that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to import module whose filename starts number

2012-12-12 Thread Benjamin Kaplan
On Dec 12, 2012 9:47 AM, "Yong Hu"  wrote:
>
> I have a few scripts whose file names start with numbers. For example,
01_step1.py, 02_step2.py
>
> I tried to import them in another script by "import 01_step1" or "from
01_step1 import *". Both failed, saying "SyntaxError: invalid syntax"
>
> Is there anyway to import those files? The file name must start with
characters?
> --

I believe the restriction is that the module names must be valid
identifiers. You may still be able to import them using __import__ and then
assign the resulting module object to a valid name.
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Robust regex

2012-11-19 Thread Benjamin Kaplan
On Nov 19, 2012 12:37 PM, "Joseph L. Casale" 
wrote:
>
> Trying to robustly parse a string that will have key/value pairs separated
> by three pipes, where each additional key/value (if more than one exists)
> will be delineated by four more pipes.
>
> string = 'key_1|||value_1key_2|||value_2'
> regex = '((?:(?!\|\|\|).)+)(?:\|\|\|)((?:(?!\|\|\|).)+)(?:\|\|\|\|)?'
>
> I am not convinced this is the most effective or safest, any opinions
would
> be greatly appreciated!
>
> jlc
> --
> http://mail.python.org/mailman/listinfo/python-list

Do you even need a regular expression for this? Just split on  and then
split those on |||.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numpy module

2012-10-29 Thread Benjamin Kaplan
On Sun, Oct 28, 2012 at 10:40 PM,   wrote:
> Hello to the group!
>
> I've learned a lot about Ubuntu just trying to install numpy for Python 
> 3.2.3. I've finally managed to put it in the Python3.2 directory but when I 
> try to import it, I still get there's "no module named numpy." There are 
> other modules in the same directory, like 'email' and it imports fine.
>
> Does Numpy 1.6.2 not run with Python 3.2.3?
>
> Can anybody help? Thank you in advance.
>
> Peter Farrell
> --

Numpy is written in C. You can't just drop the source code into a
folder. It has to be compiled against that version of Python. You
could do that yourself, or you could just run "sudo apt-get install
python3-numpy"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nice solution wanted: Hide internal interfaces

2012-10-29 Thread Benjamin Kaplan
On Mon, Oct 29, 2012 at 9:33 AM, Johannes Bauer  wrote:
> Hi there,
>
> I'm currently looking for a good solution to the following problem: I
> have two classes A and B, which interact with each other and which
> interact with the user. Instances of B are always created by A.
>
> Now I want A to call some private methods of B and vice versa (i.e. what
> C++ "friends" are), but I want to make it hard for the user to call
> these private methods.
>
> Currently my ugly approach is this: I delare the internal methods
> private (hide from user). Then I have a function which gives me a
> dictionary of callbacks to the private functions of the other objects.
> This is in my opinion pretty ugly (but it works and does what I want).
>
> I'm pretty damn sure there's a nicer (prettier) solution out there, but
> I can't currently think of it. Do you have any hints?
>
> Best regards,
> Joe
>

What do you mean "declare the internal methods private"? Python
doesn't have this notion of restricted access. By convention, names
starting with a leading underscore are private, but it's not enforced
by the language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't run any script without it failing due to calling tkinter for no reason

2012-10-14 Thread Benjamin Kaplan
On Sun, Oct 14, 2012 at 6:47 PM,   wrote:
> Hello All,
>
>
> I'm running python 3.2 on Freebsd 9.0 Release and I must've screwed up my 
> environment somehow, because now I can't run any script without it failing 
> and throwing:
> ** IDLE can't import Tkinter.  Your Python may not be configured for Tk. **
>
> Yet none of my scripts use tkinter nor call that module. They're simple 
> network scraping scripts. I use pydev and eclipse and must've fat fingered 
> something that screwed up my python environment, but I haven't the slightest 
> clue on how to fix it. I can run my scripts in idle no problem, but I've 
> built them as command line apps. I've tried uninstalling python 3 and 
> reinstalling it to no avail. What did I do, and how can I fix it?
>
> Thanks,
> Adam
> --

IDLE uses Tkinter. If you don't have Tk installed, just run the
scripts from the terminal or pick a different IDE.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Benjamin Kaplan
On Sun, Sep 30, 2012 at 12:42 PM, Peter Farrell
 wrote:
> Hello!
>
> I'm still new to Python, so here's another easy one. After I save something 
> I've done as a .py file, how do I import it into something else I work on? 
> Every time I try to import something other than turtle or math, I get this 
> error message:
>
> 'module' object is not callable
>
> What am I doing wrong?
>
> Thanks!
>
> Peter Farrell
> San Mateo, CA
> --

Well, you haven't told us what you're doing, so it's hard to say what
you're doing wrong. So I'm going to make a few guesses.

1. Your first (and possibly only other) language was Java.
2. You're making a class (let's say Foo) and putting it in a file of
the same name (Foo.py)
3. You're doing "import Foo" and then calling "Foo()" trying to
instantiate the class.

Python doesn't have that "one class per file, and the file must have
the same name as the class" rule as Java. The file defines a module,
which is an object and can have any number of objects (including
classes, because those are objects too) in it.

$ cat foo.py
class Foo(object):
pass

def add2(y) :
return y + 2
bkaplan:~ bkaplan$ python
Python 2.7.3 (default, Apr 23 2012, 10:06:17)
[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo
>>> dir(foo)
['Foo', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', 'add2', 'x']
>>> foo()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'module' object is not callable
>>> foo.Foo()

>>> foo.add2(5)
7
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing Pip onto a mac os x system

2012-09-19 Thread Benjamin Kaplan
On Sep 19, 2012 6:37 PM, "John Mordecai Dildy"  wrote:
>
> Does anyone know how to install Pip onto a mac os x ver 10.7.4?
>
> Ive tried easy_instal pip but it brings up this message (but it doesn't
help with my problem):
>
> error: can't create or remove files in install directory
>
> The following error occurred while trying to add or remove files in the
> installation directory:
>
> [Errno 13] Permission denied:
'/Library/Python/2.7/site-packages/test-easy-install-1820.write-test'
>
> The installation directory you specified (via --install-dir, --prefix, or
> the distutils default setting) was:
>
> /Library/Python/2.7/site-packages/
>
> Perhaps your account does not have write access to this directory?  If the
> installation directory is a system-owned directory, you may need to sign
in
> as the administrator or "root" account.  If you do not have administrative
> access to this machine, you may wish to choose a different installation
> directory, preferably one that is listed in your PYTHONPATH environment
> variable.
>
> For information on other options, you may wish to consult the
> documentation at:
>
>   http://peak.telecommunity.com/EasyInstall.html
>
> Please make the appropriate changes for your system and try again.
>
> Thing is I am the Administrator of the computer and can use all of the
folders on the mac computer.
>

No you can't. You can ask permission to use skill the folders (and then
grant yourself that permission), but the user that you're currently running
as does not have full access to the computer.

You know how every time you install a program, a prompt comes up asking for
your password? That's you giving the process permission to run as "root",
the only account with full access to everything.

On the command line, you run things as root by using the "sudo" command
(being an administrator means your account is able to run that)

sudo easy_install pip

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


Re: subprocess call is not waiting.

2012-09-19 Thread Benjamin Kaplan
On Sep 19, 2012 9:37 AM, "andrea crotti"  wrote:
> Well there is a process which has to do two things, monitor
> periodically some external conditions (filesystem / db), and launch a
> process that can take very long time.
>
> So I can't put a wait anywhere, or I'll stop everything else.  But at
> the same time I need to know when the process is finished, which I
> could do but without a wait might get hacky.
>
> So I'm quite sure I just need to run the subprocess in a subthread
> unless I'm missing something obvious.

If you want to see if a processes has terminated without waiting, use poll.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a python license problem?

2012-09-10 Thread Benjamin Kaplan
On Mon, Sep 10, 2012 at 7:58 PM, Jayden  wrote:
> Python is under GPL compatible. If I develop a python code, convert it to 
> executable and distribute the executable as a commercial software. May I need 
> to make my source code open?
>
> If python is under GPL, is the answer different? Thanks a lot!!
> --
> http://mail.python.org/mailman/listinfo/python-list

"GPL compatible" is not a license. It's a quality of the license.
Python's license is compatible with the GPL, which means that you can
use Python in software licensed under the GPL

Python's license (which is available at
http://docs.python.org/license.html ) does not require Python code to
be open source, nor does it prohibit commercial use.

And even if Python was under the GPL, you would still be able to
release your own programs without opening the source. You just
wouldn't be able to modify Python without releasing your changes.
That's how the userland in Mac OS X is still closed-source despite
being compiled with GCC.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie: where's the new python gone?

2012-09-10 Thread Benjamin Kaplan
On Sun, Sep 9, 2012 at 11:10 PM, Dwight Hutto  wrote:
>
> I have several installations on my windows, so I use
> c:\python27_64\python.exe module_file.py
>
> or
>
> c:\python26\python.exe module_file.py
>
> in the command line.
>
>
> Not to show that this shouldn't be a discussion, but usually it's searching.
> Here's search term a link, and some python docs:
>
> install python windows command line
>
> or click:
>
> https://www.google.com/search?q=install+python+windows+command+line&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-ahere's
>
> and one of the better results:
>
> http://docs.python.org/faq/windows.html#how-do-i-run-a-python-program-under-windows
>
>
> --
> Best Regards,
> David Hutto
> CEO: http://www.hitwebdevelopment.com
>

The problem is related to Python on Mac, not on Windows. As was stated
in the original post.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there any difference between print 3 and print '3' in Python ?

2012-09-10 Thread Benjamin Kaplan
On Sun, Sep 9, 2012 at 11:33 PM, Dwight Hutto  wrote:
>
>
> On Sun, Sep 9, 2012 at 10:41 AM, Ian Foote  wrote:
>>
>> On 09/09/12 14:23, iMath wrote:
>>>
>>> 在 2012年3月26日星期一UTC+8下午7时45分26秒,iMath写道:

 I know the print statement produces the same result when both of these
 two instructions are executed ,I just want to know Is there any difference
 between print 3 and print '3' in Python ?
>>>
>>> thx everyone
>>
>>
>
> Here's a future import though I used,so I can use the planned 3 with a 2x
> python version in the command line interpreter:
>
> Microsoft Windows [Version 6.1.7600]
> Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
>
> C:\Users\david>c:\python26\python.exe
> Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
> on
> win32
> Type "help", "copyright", "credits" or "license" for more information.
 exit()
>
> C:\Users\david>c:\python27_64\python.exe
> Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on
> win
> 32
> Type "help", "copyright", "credits" or "license" for more information.
 import __future__
 x = 3
 y = '3'
 print(x)
> 3
 print(y)
> 3

 type(x)
> 
 type(y)
> 
>
 z = '%i' % (3)
 type(z)
> 

>
> In other words type(value), and find out the difference.
> --
> Best Regards,
> David Hutto
> CEO: http://www.hitwebdevelopment.com
>

Somewhat OT, but __future__ doesn't work like that. You have to import
the specific features you want to use.

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> print 3
3
>>> import __future__
>>> print 3
3
>>> from __future__ import print_function
>>> print 3
  File "", line 1
print 3
  ^
SyntaxError: invalid syntax
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing dll

2012-09-06 Thread Benjamin Kaplan
On Sep 6, 2012 8:15 AM, "Helpful person"  wrote:
>
> I am a complete novice to Python.  I wish to access a dll that has
> been written to be compatible with C and VB6.  I have been told that
> after running Python I should enter  "from ctypes import *" which
> allows Python to recognize the dll structure.  I have placed the dll
> into my active directory (if that's the correct word, one on my path)
> for simplification.
>
> I tried:   "import name.dll" but this just gave me an error telling me
> that there was no such module.
>
> Can someone please help?
>
> Richard
> --

Two things:

1) you would never use import name.dll, just like you don't use "import
math.py" you would just import name. But that only works for Python
libraries, which brings us to number 2

2) importing ctypes doesn't work any magic. Your c library is still a c
library, not a python library. Ctypes provides functions to let you load a
dll and makes calls to it, but you can't interact with the dll like python
code. Doing that takes a lot more work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why did the WindowsError occur?

2012-09-04 Thread Benjamin Kaplan
On Tue, Sep 4, 2012 at 11:30 PM, Levi Nie  wrote:
> my code:
> import os
> os.startfile(r'C:\Program Files\Internet Explorer.exe')
>
> the error:
> os.startfile(r'C:\Program Files\Internet Explorer.exe')
> WindowsError: [Error 2] : 'C:\\Program Files\\Internet Explorer.exe'
>

There's no such thing as C:\Program Files\Internet Explorer.exe. You
probably want C:\Program Files\Internet Explorer\iexplore.exe.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is implemented with id ?

2012-09-04 Thread Benjamin Kaplan
On Tue, Sep 4, 2012 at 11:30 PM, Franck Ditter  wrote:
> Hi !
> a is b <==> id(a) == id(b) in builtin classes.
> Is that true ?
> Thanks,
>
> franck

No. It is true that if a is b then id(a) == id(b) but the reverse is
not necessarily true. id is only guaranteed to be unique among objects
alive at the same time. If objects are discarded, their ids may be
reused even though the objects are not the same.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: popen4 - get exit status

2012-08-27 Thread Benjamin Kaplan
On Aug 27, 2012 3:47 PM, "Tim Johnson"  wrote:
>
> In bash I do the following:
> linus:journal tim$ /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup
> -bash: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or
directory
> linus:journal tim$ echo $?
> 127
>
> In python, use os.popen4 I do the following:
> >>> fin,fout =
os.popen4('/home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup;echo $?')
> >>> results = fout.readlines()
> >>> results
> ['/bin/sh: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file
or directory\n', '127\n']
>
> Well, I got the exit code as the last item in the results, but I'm
wondering if
> there is a better way. From help(os) - I don't find any variables
dedicated to
> holding exit status.
>
> Any ideas?
> thanks
> --
> Tim
> tim at tee jay forty nine dot com or akwebsoft dot com
> http://www.akwebsoft.com

The popen* functions are deprecated. You should use the subprocess module
instead.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to convert base 10 to base 2?

2012-08-20 Thread Benjamin Kaplan
On Mon, Aug 20, 2012 at 12:50 AM,   wrote:
> Hi,
> as you can argue from the subject, i'm really,really new to python.
> What is the best way to achieve that with python? Because the syntax 
> int('30',2) doesn't seem to work!

That syntax goes the other way- from a string representing a number in
the given base into an integer (which doesn't have a base, although
it's stored in base 2).

You get the binary by doing bin(x), where x is an integer.

>>> bin(12)
'0b1100'

If you want to go from a string in base-10 to a string in base-2, you
have to do the conversion to integer first.

>>> bin(int('5',10))
'0b101'

Although you don't need to specify the 10 because that's the default.
>>> bin(int('5'))
'0b101'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to fix error "Requires python(abi)=2.4"

2012-08-14 Thread Benjamin Kaplan
On Aug 14, 2012 4:51 AM, "sagarnikam123"  wrote:
>
> i am installing numpy on fedora with python 2.6,2.7 & 3.1
>
>
>
> --

Python bytecode and C interface are not compatible across versions. If
you're trying to install a numpy binary that was compiled against 2.4, it
won't work with newer versions. You either need to find binaries compiled
against a version of python you have or compile numpy yourself
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Idle no longer works

2012-08-11 Thread Benjamin Kaplan
On Sat, Aug 11, 2012 at 4:09 PM, Opap-OJ  wrote:
> I can no longer open the Idle IDE for Python on Windows 7.
>
> For 3-5 years I used Idle for all my python work.  But in January this 
> happens:
>
> When I right click on a python file and choose "open with Idle" nothing 
> happens.
>
> If I double-click on the file itself, it briefly opens an MS-DOS looking 
> window, then closes it immediately.
>
> I tried installing Eclipse with PyDev.  It opens the file, but will not run 
> it in Python.
>
> Any idea why?
> --

Have you tried launching Python from the Command Prompt? Open up
command prompt and run C:\Python32\python.exe or whatever corresponds
to your version of Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I thought I understood how import worked...

2012-08-07 Thread Benjamin Kaplan
On Aug 7, 2012 8:41 AM, "Roy Smith"  wrote:
>
> On Tuesday, August 7, 2012 9:55:16 AM UTC-4, Ben Finney wrote:
>
> >  The tutorial is misleading on this. It it says plainly:
> >
> > A module can contain executable statements as well as function
> > definitions. […] They are executed only the *first* time the module
> > is imported somewhere.
> >
> > http://docs.python.org/tutorial/modules.html>
>
> That's more than misleading.  It's plain wrong.  The example I gave
demonstrates the "print __file__" statement getting executed twice.
>
> The footnote to that is wrong too:
>
> > [1]   In fact function definitions are also ‘statements’ that are
‘executed’; the execution of a
> > module-level function enters the function name in the module’s global
symbol table.
>
> I think what it's supposed to say is "... the execution of a module-level
def statement ..."
>
> > Care to file a documentation bug http://bugs.python.org/>
> > describing this?
>
> Sure, once I understand how it's really supposed to work :-)
>
> --

Each module only gets imported once. But if the same module can be accessed
as two different names, python doesn't recognize that they are the same
module. Along the same lines, if you create a symlink to the file, you'll
be able to import the same module twice.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help

2012-07-19 Thread Benjamin Kaplan
On Jul 19, 2012 4:04 PM, "Miriam Gomez Rios" 
wrote:
>
> Hello, sorry for bothering you, but I have a doubt,
>
> Is there a way to turn this string into a tuplelist??, I need it for
gurobi
>
>
('per1','persona1.1','pro1'),('per1','persona1.1','pro2'),('per1','persona1.1','pro3'),('per1','persona1.1','pro4'),('per1','persona1.1','pro5'),('per2','persona2.1','pro1'),('per2','persona2.1','pro2'),('per2','persona2.1','pro3'),('per2','persona2.1','pro4'),('per2','persona2.1','pro5'),('per2','persona2.2','pro1'),('per2','persona2.2','pro2'),('per2','persona2.2','pro3'),('per2','persona2.2','pro4'),('per2','persona2.2','pro5'),('per2','persona2.3','pro1'),('per2','persona2.3','pro2'),('per2','persona2.3','pro3'),('per2','persona2.3','pro4'),('per2','persona2.3','pro5'),('per2','persona2.4','pro1'),('per2','persona2.4','pro2'),('per2','persona2.4','pro3'
>
> the string is made with fors, using data from another file, and I need it
as a tuplelist
>
> Thank you
>
>
> --

It looks like you can just put brackets around it and call ast.literal_eval.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to compile pygtk in python2.7?

2012-07-07 Thread Benjamin Kaplan
On Sat, Jul 7, 2012 at 9:47 PM, contro opinion  wrote:
> 1.download  pygtk
>
> 2.cd /home/tiger/pygtk-2.24.0
>
> 3.PYTHON=/usr/bin/python2.7  ./configure --prefix=/usr
> 4. make
> 5. make install
>
> tiger@ocean:~$ python2.7
> Python 2.7.3 (default, Jul  1 2012, 14:13:18)
> [GCC 4.4.5] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 import gtk
> Traceback (most recent call last):
>   File "", line 1, in 
> ImportError: No module named gtk

>
>  i can't compile pygtk in python2.7,how to compile it?
>
> --

What is the output of make and make install? Does it compile
successfully, or is there an error? Does the current user have
permission to write to /usr?

You haven't given us enough information to figure out what's going on?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: moving methods from class to instance of other class

2012-06-28 Thread Benjamin Kaplan
On Wed, Jun 27, 2012 at 11:59 PM, lars van gemerden
 wrote:
> Hi all,
>
> I have some trouble with the following question: Let say i have the
> following classes:
>
> class A(object):
>    def __init__(self):
>        self.name = 'a'
>    def do(self):
>        print 'A.do: self.name =', self.name
>
> class B(object):
>    def __init__(self):
>        self.name = 'b'
>
>
>
> The question is: How do i move the 'do' method from A to b (resulting
> in  printing "A.do: self.name = b")?
>
> I have tried (with a = A() and b  B()):
>
> B.do = types.MethodType(A.do, b) #Error
>
> and stuff like:
>
> b.do = a.do
> b.do()
>
> But either i get an error or b.do() prints  "A.do: self.name = a", so
> the self parameter of a.do is stored somehow in the method.
>
> In other words, how do i unbind 'do' from a/A and bind it to b (the
> instance)?
>
> Cheers, Lars
>

Is there any particular reason you can't just have B be a subclass of
A? You could do

b.do = types.MethodType(A.do.im_func, b, B)

but there's no point in re-inventing the wheel.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there any way to decode String using unknown codec?

2012-06-27 Thread Benjamin Kaplan
On Wed, Jun 27, 2012 at 6:14 PM,   wrote:
> Hi
> I'm a Korean and when I use modules like sys, os, &c,
> sometimes the interpreter show me broken strings like
> '\x13\xb3\x12\xc8'.
> It mustbe the Korean "alphabet" but I can't decode it to the rightway.
> I tried to decode it using codecs like cp949,mbcs,utf-8
> but It failed.
> The only way I found is eval('\x13\xb3\x12\xc8').
> It raises an Error with showing right Korean.
> Is there any way to deal it being not broken?
> --

It's not broken. You're just using the wrong encodings. Try utf-16le.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Python Scripts on Mac using Python Launcher

2012-06-26 Thread Benjamin Kaplan
On Tue, Jun 26, 2012 at 10:19 AM, David Thomas  wrote:
> I have installed Python 2.7.3 from Python.org also in Terminal it states that 
> I have 2.7.3.
> How can I execute the script from Terminal?  I've tried typing python into 
> the window and then dragging the file to terminal but I get a syntax error.  
> Sorry I am new to Python and just want to know how I can open such a file 
> using 10.7.
>
> Thanks
>
> http://www.freeimagehosting.net/ilbqt
> http://www.freeimagehosting.net/r5ars

My guess would be that you're getting a SyntaxError when you run it
through the Launcher too. WIthout seeing the script, I don't know why
that would is.

I can tell you one thing you're doing wrong. Never, ever, use input()
in Python 2. If you do, all someone has to do is type in
__import__('os').remove(__file__) and stuff starts getting deleted.
"input" interprets what it reads in. Use raw_input() instead, which
always returns a string.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perl __DATA__ construct.

2012-06-25 Thread Benjamin Kaplan
On Mon, Jun 25, 2012 at 2:20 PM, Mladen Gogala  wrote:
> I have a script in Perl that I need to rewrite to Python. The script
> contains __DATA__ at the end of the script, which enables Perl to access
> all the data after that through a file descriptor, like this:
>
> usage() if ( !$stat or !defined($home) or !defined($base) or !defined
> ($sid) );
> while () {
>    s/%OB/$base/;
>    if ( length($home) > 0 ) {
>        s/%OH/$home/;
>    }
>    else {
>        s/\/%OH$//;
>    }
>    if ( length($sid) > 0 && /%OS/ ) {
>        s/%OS/$sid/;
>    }
>    elsif (/%OS/) {
>        next;
>    }
>    s/%VR/$ver/;
>    print;
> }
> __DATA__
> # .bashrc
> # Source global definitions
> if [ -f /etc/bashrc ]; then
>        . /etc/bashrc
> fi
> set -a
>
> # User specific aliases and functions
> export PATH=/sbin:/bin:/usr/sbin:$PATH
> export EDITOR=vi
> export ORACLE_BASE=%OB
> export ORACLE_HOME=$ORACLE_BASE/product/%VR/%OH
> export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/opt/odbc/lib:$ORACLE_HOME/lib32
> export CLASSPATH=/opt/java/lib/tools.jar:$ORACLE_HOME/jdbc/lib/
> ojdbc14.jar:.
>
> ..
>
>
>
> How do I do the same thing in Python? Alternatively, in Perl I can put an
> entire file into a string by using something like:
>
> $str=< This is all a single string,
> no matter how many lines do
> I put in it, but I do have to
> escape the special character
> EOF
> ;
>
> Is there a way to do the same thing in Python? The idea of the script is
> to generate $HOME/.bashrc for any automagically provisioned Oracle
> installation.
>
either escape the new-line
'hello \
world'

or use triple-quoted strings
"""hello
world"""

http://docs.python.org/tutorial/introduction.html#strings
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Python Scripts on Mac using Python Launcher

2012-06-25 Thread Benjamin Kaplan
On Mon, Jun 25, 2012 at 11:19 AM, David Thomas  wrote:
> Hello,
> This is my first post so go easy on me.  I am just beginning to program using 
> Python on Mac.  When I try to execute a file using Python Launcher my code 
> seems to cause an error in terminal, when I execute the exact same piece of 
> code and run it in windows it seems to execute as exactly intended.
>  How can I make my python script to open up correctly using Python Launcher?  
> I am running 10.7 on my Mac.  I would upload a photo with the error I get but 
> I can't seem to find the upload feature in this group.
>
> Thanks
> --

You can't find the upload feature because this isn't a Google Group.
It's a Usenet newsgroup that Google Groups provides access to that's
also available as a mailing list. If you want to provide an image, use
an image host and link to the image.

As to your question, I have a few questions of my own. What version of
Python are you using? Is it the version included in Mac OS X,
installed from a python.org binary, compiled by source, or installed
through a package manager? What happens if you call the script from
the command line instead of using the Launcher application?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: None shown in output

2012-06-21 Thread Benjamin Kaplan
damn

On Thu, Jun 21, 2012 at 9:24 PM, Benjamin Kaplan
 wrote:
> On Thu, Jun 21, 2012 at 8:42 PM, Xander Solis  wrote:
>> Hello Python list,
>>
>> Noob here with a newbie question. I'm reading and working on the exercise of
>> the book, Learn Python the Hard way 2.0. When I use this code, I get "None"
>> on the output. My question is why does this happen?
>>
>> def get_numbers(first_num, second_num, operator):
>>
>>     if operator == 'add':
>>         print first_num + second_num
>>     elif operator == 'minus':
>>         print first_num - second_num
>>     elif operator == 'divide':
>>         print first_num / second_num
>>     elif operator == 'multiply':
>>         print first_num * second_num
>>
>> print "%r" % (get_numbers(1, 2, 'minus'))
>> print "%r" % (get_numbers(1+3, 2+9, 'add'))
>> print "%r" % (get_numbers(10, 2, 'divide'))
>>
>> Output:
>>
>> C:\code\python>ex19.py
>> -1
>> None
>> 15
>> None
>> 5
>> None
>> 7.5
>>
>> --
>>
>> Thanks in advance for your help.
>>
>> Regards,
>>
>> Xander
>>
>
> printing something just writes the value to th

I hate when I accidentally hit send early. Anyway, Michael already
gave you the reason- print and return two different things.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: None shown in output

2012-06-21 Thread Benjamin Kaplan
On Thu, Jun 21, 2012 at 8:42 PM, Xander Solis  wrote:
> Hello Python list,
>
> Noob here with a newbie question. I'm reading and working on the exercise of
> the book, Learn Python the Hard way 2.0. When I use this code, I get "None"
> on the output. My question is why does this happen?
>
> def get_numbers(first_num, second_num, operator):
>
>     if operator == 'add':
>         print first_num + second_num
>     elif operator == 'minus':
>         print first_num - second_num
>     elif operator == 'divide':
>         print first_num / second_num
>     elif operator == 'multiply':
>         print first_num * second_num
>
> print "%r" % (get_numbers(1, 2, 'minus'))
> print "%r" % (get_numbers(1+3, 2+9, 'add'))
> print "%r" % (get_numbers(10, 2, 'divide'))
>
> Output:
>
> C:\code\python>ex19.py
> -1
> None
> 15
> None
> 5
> None
> 7.5
>
> --
>
> Thanks in advance for your help.
>
> Regards,
>
> Xander
>

printing something just writes the value to th
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "constant sharing" works differently in REPL than in script ?

2012-06-18 Thread Benjamin Kaplan
On Mon, Jun 18, 2012 at 7:52 PM,   wrote:
> Listening to 'Radio Free Python' episode 8 
> (http://radiofreepython.com/episodes/8/ - around about the 30 minute mark) I 
> heard that Python pre creates some integer constants to avoid a proliferation 
> of objects with the same value.
>
> I was interested in this and so I decided to try it out.
>
> First I did this at the prompt :
>
 c = 1
 print id(1)
> 26906152
 print id(c)
> 26906152
 c is 1
> True
>
> So that matched what I'd heard and then I did this to test the limits of it :
>
 c = 259
 print id(259)
> 26167488
 print id(c)
> 26167512
 c is 259
> False
>
> And that was reasonable too as the podcast mentioned it was only done for a 
> small set of integers around zero.
>
> However when I wrote this script :
>
> c = 259
> print id(259)
> print id(c)
> if c is 259:
>    print "%s - yes" % (c)
> else:
>    print "%s - no " % (c)
>
> I got this output :
>
> C:\data\src\Python\foo>python untitled-2.py
> 26760884
> 26760884
> 259 - yes
>
> So what's going on here. The script seems to be sharing objects in a way the 
> REPL isn't ?
>
> Can anyone explain please ?
>
> BTW this is all on : Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC 
> v.1500 32 bit (Intel)] on win32 .
>

Python the language doesn't specify anything about this sort of
behavior. CPython the implementation does all sorts of optimizations
to make code run more efficiently. Caching integers is one of those
optimizations. In the case where the code is compiled all at once (as
in the script) instead of one line at a time (the REPL), it can do
more optimizations. But as I said, none of this is in the
specification so you shouldn't rely on it. The general rule for the
"is" operator is that unless you specifically know that you need it,
don't use it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read STDIN as bytes rather than a string

2012-06-18 Thread Benjamin Kaplan
On Mon, Jun 18, 2012 at 4:13 PM, Jason Friedman  wrote:
> I tried this:
>
> Python 3.2.2 (default, Feb 24 2012, 20:07:04)
> [GCC 4.6.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 import sys
 import io
 fh = io.open(sys.stdin)
> Traceback (most recent call last):
>  File "", line 1, in 
> TypeError: invalid file: <_io.TextIOWrapper name='' mode='r'
> encoding='UTF-8'>
 fh = io.open(sys.stdin, "rb")
> Traceback (most recent call last):
>  File "", line 1, in 
> TypeError: invalid file: <_io.TextIOWrapper name='' mode='r'
> encoding='UTF-8'>
> --

You want to read from sys.stdin.buffer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Py3.3 unicode literal and input()

2012-06-18 Thread Benjamin Kaplan
On Mon, Jun 18, 2012 at 1:19 AM, jmfauth  wrote:
> What is input() supposed to return?
>
 u'a' == 'a'
> True

 r1 = input(':')
> :a
 r2 = input(':')
> :u'a'
 r1 == r2
> False
 type(r1), len(r1)
> (, 1)
 type(r2), len(r2)
> (, 4)

>
> ---
>
> sys.argv?
>
> jmf

Python 3 made several backwards-incompatible changes over Python 2.
First of all, input() in Python 3 is equivalent to raw_input() in
Python 2. It always returns a string. If you want the equivalent of
Python 2's input(), eval the result. Second, Python 3 is now unicode
by default. The "str" class is a unicode string. There is a separate
bytes class, denoted by b"", for byte strings. 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.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Passing ints to a function

2012-06-08 Thread Benjamin Kaplan
On Fri, Jun 8, 2012 at 7:41 PM, stayvoid  wrote:
> Hello,
>
> I want to pass several values to a function which is located on a
> server (so I can't change its behavior).
> That function only accepts five values which must be ints.
>
> There are several lists:
> a = [1, 2, 3, 4, 5]
> b = [5, 4, 3, 2, 1]
> c = [0, 0, 0, 0, 0]
>
> I want to pass each value from these lists to that function.
> What is the most pythonic way?
>

function(*a)

* expands a list into positional arguments and ** expands a dictionary
into keyword arguments.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where is the latest step by step guide to use Jython to compilePython into Java?

2012-06-04 Thread Benjamin Kaplan
On Mon, Jun 4, 2012 at 11:47 AM, David Shi  wrote:
> Hello, Mohan,
>
> Did you test it?  I am using Windows.  Where are the exact steps for
> compiling in DOS?
>
> Once .class or jar files created, how to use these files?
>
> Could you enlighten me with tested/proven step by step instructions?
>
> Regards.
>
> David
>
> ___

David,

Jythonc has been deprecated for years and hasn't been included with
Jython since 2.2. Nor does it support any language feature newer than
2.2. I don't think anyone managed to get the python to JVM byte code
compiler working either since JVM byte code is notoriously bad for
things that don't behave like Java.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing Mailman

2012-06-03 Thread Benjamin Kaplan
On Mon, Jun 4, 2012 at 12:49 AM, Chris Rebert  wrote:
> On Sun, Jun 3, 2012 at 9:04 PM, Janet Heath
>  wrote:
>> checking for --with-python... no
>> checking for python... /usr/bin/python
>> checking Python interpreter... /usr/bin/python
>> checking Python version... 2.7.1
>> checking Python's email package... ok
>> checking Japanese codecs... ok
>> checking Korean codecs... ok
>> checking that Python has a working distutils... configure: error:
>>
>> * Distutils is not available or is incomplete for /usr/bin/python
>> * If you installed Python from RPM (or other package manager)
>> * be sure to install the -devel package, or install Python
>> * from source.  See sec. 15.1 of the Installation Manual for
>> * details
>>
>> When I try to check the configuration ./configure for Mailman, I get
>> the above messages.
>
> What *nix flavor or Linux distro are you running?
>
> Cheers,
> Chris

Based on the previous post (./configure), I would assume OS X Lion. I
would also assume she gave up on compiling 2.7.3 herself because it's
only finding the system Python.

Janet, did you install the binary from http://www.python.org? If so,
look up the --with-python argument it's checking for (./configure
--help) and set the Python location accordingly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ./configure

2012-06-03 Thread Benjamin Kaplan
>
> Thanks Alain.  I should have a compiler on my Mac OS X Lion.  I am thinking 
> that it isn't set in my $PATH variable.  I don't know where the $PATH is set 
> at.  I will check to see if their is a binary.
> --
> http://mail.python.org/mailman/listinfo/python-list

You need to install the command line tools package within XCode in
order to get them on the path. Or, I guess you could just add XCode's
bin directory to the path. It's usually set in ~/.bash_profile

Or you could just use the binary installer from
http://python.org/download/releases/2.7.3/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to import Webkit and object in Official Python (not MacPorts python) without X11.

2012-05-26 Thread Benjamin Kaplan
On Sat, May 26, 2012 at 9:31 AM, Mr.T Beppu  wrote:
> I think that I will make a browser in Official Python (not MacPorts
> Python).
> What should I do in order to install Webkit for Official Python (not
> MacPorts Python) ?
> from tokyo Japan.
>

You don't just "install WebKit". You need a GUI framework. My
suggestion would be to install PySide, which is a QT wrapper that
includes a Webkit component. The other option is to use PyObjC to
build a Cocoa GUI but then you're restricted to Mac OS X only.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: install python 2.6 on Ubuntu 12.04

2012-05-22 Thread Benjamin Kaplan
On Tue, May 22, 2012 at 8:09 PM, Dan Stromberg  wrote:
>
> If the pythons you require are in synaptic (sudo to root and run synaptic),
> you probably can just use them.
>
> If not, then you, for each release, need to:
> 1) download a tarball using a browser or whatever
> 2) extract the tarball: tar xvfp foo.tar.bz2
> 3) cd into the newly created, top-level directory, and run ./configure
> --prefix /usr/local/cpython-2.6 (or similar)
> 4) Run "make", optionally with parallelism; I often use number_of_cores+1,
> so for a quad core system, I might use "make -j 5".  This speeds up the
> build.
> 5) Run /usr/local/cpython-2.6/bin/python - just to make sure it gives a
> prompt.  control-d to exit.
> 6) Try running your script with one of your new python builds:
> /usr/local/cpython-2.6/bin/python my-script
>
> I've done this for 2.5, 2.6, 2.7, 3.0, 3.1, 3.2 and the 3.3 preview stuff.
> They cooperate with each other well.  Actually, I scripted out the build so
> that I'd get all 7 built automatically with cython and pylint in them.
>
>

Even easier:

./configure
make
sudo make altinstall

If I recall correctly, that will install it in
/usr/local/lib/python2.6 and it will create /usr/local/bin/python2.6
but it will not create /usr/local/bin/python so it won't clobber the
system python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: %d not working in re at Python 2.7?

2012-05-14 Thread Benjamin Kaplan
On May 14, 2012 7:06 PM, "vacu"  wrote:
>
> I am frustrated to see %d not working in my Python 2.7 re.search, like
> this example:
>
> >>> (re.search('%d', "asdfdsf78asdfdf")).group(0)
> Traceback (most recent call last):
>  File "", line 1, in 
> AttributeError: 'NoneType' object has no attribute 'group'
>
>
> \d works fine:
>
> >>> (re.search('\d+', "asdfdsf78asdfdf")).group(0)
> '78'
>
>
> And google search ignores % in their search, so I failed to find
> answer from Python mailing list or web,
> Do you have any idea what's problem here?
>
> Thanks a head
> Vacu
> --

There's no problem at all. This is re.search, not scanf. They aren't
supposed to behave the same. In fact, the docs specifically describe how to
simulate scanf using re because python doesn't have a scanf function.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some posts do not show up in Google Groups

2012-04-29 Thread Benjamin Kaplan
On Mon, Apr 30, 2012 at 2:20 AM, Frank Millman  wrote:
>
> Hi all
>
> For a while now I have been using Google Groups to read this group, but on
> the odd occasion when I want to post a message, I use Outlook Express, as I
> know that some people reject all messages from Google Groups due to the high
> spam ratio (which seems to have improved recently, BTW).
>
> >From time to time I see a thread where the original post is missing, but
> the follow-ups do appear. My own posts have shown up with no problem.
>
> Now, in the last month, I have posted two messages using Outlook Express,
> and neither of them have shown up in Google Groups. I can see replies in OE,
> so they are being accepted. I send to the group gmane.comp.python.general.
>
> Does anyone know a reason for this, or have a solution?
>
> Frank Millman

I believe the mail-to-news gateway has trouble with HTML messages. Try
sending everything as plain text and see if that works.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why () is () and [] is [] work in other way?

2012-04-23 Thread Benjamin Kaplan
On Mon, Apr 23, 2012 at 1:01 PM, Paul Rubin  wrote:
>
> Kiuhnm  writes:
> > I can't think of a single case where 'is' is ill-defined.
>
> If I can't predict the output of
>
>    print (20+30 is 30+20)  # check whether addition is commutative
>    print (20*30 is 30*20)  # check whether multiplication is commutative
>
> by just reading the language definition and the code, I'd have to say
> "is" is ill-defined.
>

The "is" operator is perfectly defined. But it doesn't check to see
whether two objects hold equivalent values, it checks whether they are
the same thing. You're not interested in whether 20+30 and 30+20 are
the same object, you're interested in whether they return equivalent
values which should be checked with ==.

> > You're blaming 'is' for revealing what's really going on. 'is' is
> > /not/ implementation-dependent. It's /what's going on/ that's
> > implementation-dependent.
> > "a is b" is true iff 'a' and 'b' are the same object. Why should 'is'
> > lie to the user?
>
> Whether a and b are the same object is implementation-dependent.
> --

And if I try running "from java.util import ArrayList" in CPython it
will give me an import error. It doesn't mean that the import
mechanism is broken because it returns different results in different
implementations of Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: system call that is killed after n seconds if not finished

2012-04-16 Thread Benjamin Kaplan
On Mon, Apr 16, 2012 at 10:51 AM, Jaroslav Dobrek
 wrote:
>
> Hello,
>
> I would like to execute shell commands, but only if their execution
> time is not longer than n seconds. Like so:
>
> monitor(os.system("do_something"), 5)
>
> I.e. the command do_somthing should be executed by the operating
> system. If the call has not finished after 5 seconds, the process
> should be killed.
>
> How could this be done?
>
> Jaroslav

* Use subprocess instead of os.system. subprocess doesn't block
* run the process in another thread and have that thread do nothing
until the process is finished or a terminate flag gets set. If the
flag gets set, call terminate() on the Popen object.
* have the main thread call thread.join(5) on your new thread. After
that, set the terminate flag.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trac.util

2012-04-11 Thread Benjamin Kaplan
On Wed, Apr 11, 2012 at 4:52 PM, cerr  wrote:
>
> Hi,
>
> I want to install some python driver on my system that requires trac.util
> (from Image.py) but I can't find that anywhere, any suggestions, anyone?
>
> Thank you very much, any help is appreciated!
>
> Error:
> File "/root/weewx/bin/Image.py", line 32, in 
>    from  trac.util import escape
> ImportError: No module named trac.util
>
>
> Ron
> --

Trac is a project management program. I'm not sure why anything other
than a Trac plugin would have it as a dependency, but there is a
trac.util.escape defined in there.


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


Re: Question on Python 3 shell restarting

2012-04-10 Thread Benjamin Kaplan
On Tue, Apr 10, 2012 at 2:36 PM, Franck Ditter  wrote:
> In article
> <19745339.1683.1333981625966.JavaMail.geo-discussion-forums@yncc41>,
>  Miki Tebeka  wrote:
>
>> > How may I get a fresh Python shell with Idle 3.2 ?
>> Open the configuration panel (Options -> Configure IDLE).
>> Look in the "Keys" tab for the shortcut to "restart-shell"
>
> Fine, thanks, but WHY isn't it in a menu (e.g. Debug) ?
> Moreover, I see :
>
>    restart-shell - 
>
> Hum, but when I press, Ctl-F6, nothing happens !!??!! F6 gives me char.
> (MacOS-X Lion, France, Idle 3.3.0a2)
>
> I tried to replace "restart-shell " with F6 (which does nothing except 
> displaying a
> strange character inside a square), but that was refused "already in use"...
>
>    franck
>
> P.S. There is no "configuration panel (Options -> Configure IDLE)",
> only a Preferences menu with a "Key" tab on MacOS-X. May I suggest to the
> Python Idle 3 team to test their software on a Mac ? Please :-)


IDLE is tested on the Mac. But Mac OS X has very different design
guidelines from programs on other systems. The Preferences menu is
pretty much required to be under the Program Name menu, for example.
And all the keyboard shortcuts that use Ctrl on Windows and Linux use
Command on Mac OS X. If you don't specify Mac, we're going to give you
the options that work on Windows and Linux.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Run once while loop

2012-04-04 Thread Benjamin Kaplan
On Wed, Apr 4, 2012 at 9:21 AM, Anatoli Hristov  wrote:
> I thing the best will be if I use hundreds of the seconds to print the
> message.
>
> for example at 12:00:00:10, but unfortunately I cant see that I can use
> hundreds of the seconds.
>
> Does anyone knows if I can use it ?
>
> Thanks
>
> Anatoli
>
>

Your proposed solution is one of those hacks that will cause your
program to fail if we get better machines that could run that loop
twice in 1/100th of a second. "When the only tool you have is a
hammer, every problem looks like a nail". You need to add more tools
to your toolbox than an infinite loop. If your problem is that you
want to trigger an event at a specific time, John's answer is the
correct one. If your entire program is just this recurring task, use
your OS's task scheduler (Task Scheduler for Windows, Launchd for Mac
OS X, and Cron for other *nixes).

> On Wed, Apr 4, 2012 at 2:25 PM, John O'Hagan 
> wrote:
>>
>> On Tue, 3 Apr 2012 23:00:22 +0200
>> Anatoli Hristov  wrote:
>>
>> > On 03 Apr 2012, at 22:45, Ian Kelly  wrote:
>> >
>> > > On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov 
>> > > wrote:
>> > >> Hi,
>> > >>
>> > >> I'm trying to do a while loop with condition of time if time is
>> > >> 12:00:00 print text, but for this one second the text is printed at
>> > >> least 50 times, how can I print only once?
>> > >
>> > > Set a flag when you print the text to indicate that you've already
>> > > printed it, and don't print it again if the flag is set.  When it's no
>> > > longer 12:00:00, reset the flag.
>> > >
>> > > That said, a busy while loop is probably the wrong way to do this,
>> > > because it will run your CPU at 100%.  Better would be to put the
>> > > thread to sleep with time.sleep() calls or a real event loop with a
>> > > timer event.
>> > >
>> > > Cheers,
>> > > Ian
>> >
>> > Thank you Ian,
>> >
>> > what if I wait for other conditions if I use time.sleep for 1 sec? it
>> > means that all the program is sleeping for a sec.
>> >
>>
>> If I understand correctly, you don't want the whole program to sleep. If
>> that's the case, you could use threading.Timer, for example:
>>
>> import threading, time
>>
>> def twelve():
>>    print("It's twelve o'clock")
>>
>> local_secs = (time.time() - time.timezone) % (24 * 60 * 60)
>> secs_till_12 = 12 * 60 * 60 - (local_secs % (12 * 60 * 60))
>>
>> wait_till_12 = threading.Timer(secs_till_12, twelve)
>> wait_till_12.start()
>>
>>
>> Regards,
>>
>> John
>> --
>> 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: Installing Python Apps on Mac Lion

2012-03-13 Thread Benjamin Kaplan
On Tue, Mar 13, 2012 at 12:42 PM,  wrote:
>
> Sábado, 25 de Junho de 2011 02h20min49s UTC+1, JKPeck escreveu:
> > The Lion version of the OS on the Mac comes with Python 2.7 installed,
> > but it is in /System/Library/Frameworks/..., and this area is not writable
> > by third party apps.
> >
> > So is there a consensus on what apps that typically install under the
> > Python site-packages directory should do in this situation?  Installing
> > Python from python.org puts it in the writable area
> > /Library/Frameworks/Python.framework.
> >
> > So, what should a Python app installer do?
> >
> > Thanks
>
> Hello,
>
> currently I have:
>
> /Library/Python/2.7/
> /Library/Frameworks/Python.framework/Versions/2.7/
> /Users/user/Library/Python/2.7/
>
> With 3 folders "site-packages" and do not know why.
> What's the difference?
>
> Thanks.
>

If I had to take a guess, having not played too much with Lion:

/Library/Python/2.7 is for user-installed packages for the system
python that are installed for all users.
/Library/Frameworks/... is for the user-installed Python (that's where
it's always gone)
/Users/user/Library... is for user-installed packages for the system
Python that are only installed for the specific user.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's the best way to write this regular expression?

2012-03-07 Thread Benjamin Kaplan
On Wed, Mar 7, 2012 at 4:11 PM, John Salerno  wrote:
>
> On Wed, Mar 7, 2012 at 3:01 PM, Ian Kelly  wrote:
>
> > There is a fork of setuptools called "distribute" that supports Python
> > 3.
>
> Thanks, I guess I'll give this a try tonight!
>
> > setup.py is a file that should be included at the top-level of the
> > .tar files you downloaded.  Generally, to install something in that
> > manner, you would navigate to that top-level folder and run "python
> > setup.py install".  If you have multiple Python versions installed and
> > want to install the package for a specific version, then you would use
> > that version of Python to run the setup.py file.
>
> The only files included in the .tar.gz file is a .tar file of the same
> name. So I guess the setup option doesn't exist for these particular
> packages. I'll try "distribute" tonight when I have some time to mess
> with all of this.
>
> So much work just to get a 3rd party module installed!
> --


It's because your extraction program is weird. Gzip is a compression
algorithm that operates on a single file. Tar is an archive format
that combines multiple files into a single file. When we say "extract
the .tar.gz", what we mean is both uncompress the tar file and then
extract everything out of that. A lot of programs will do that in one
step. If you look inside the tar file, you should find the setup.py.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   6   7   8   >