Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread wxjmfauth
From all the toolkits, wxPython is probably the most
interesting. I used all versions from 2.0 (?) up to 2.8. Then
it has been decided to go unicode.

Let see in the wx interactive intepreter, it is only
the top of the iceberg. (Py27, wxPy294)

>>> len('ሴЃ')
5

---

It has alos been decided to rework wxPython and create
wxPhoenix, unicode of course.

Impossible to put a Python string correctly in a widget
supposed to handle text. The design mistake is more
deeper than in wx29 (unicode).

I do not know the present status, but as the mistake
is a consequence of a unicode non understanding (plus
a little bit Python, plus a little bit wxWidgets), I doubt
that some improvement happened.

I attempted to explain unicode...

jmf
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Christian Gollwitzer

Am 17.12.13 06:37, schrieb Rick Johnson:

On Sunday, December 15, 2013 11:01:53 AM UTC-6, Steven D'Aprano wrote:

low-level language with some interface to Python. The main
difference between this hypothetical "Python GUI" and Tcl
is that Tcl is a Turing-complete interpreter which lives
in it's own process.


And how many times would you take advantage of that "turning
complete" functionality in reality? My answer... ZERO! How
many Tcl calls have you, or anybody, made that did have
direct business with creating or managing a TK gui? HOW
MANY???


There are some useful extensions to Tk written in Tcl. For example, 
there is tablelist - a tree widget or multicolumn listbox in pure Tcl. 
By passing it to the Tcl interpreter, you can wrap it up for Python - 
that's what Kevin Walzer did at


http://tkinter.unpythonic.net/wiki/TableListWrapper

It would take many man-month to reproduce this thing in Python.


Another example is the file open dialog (import tkFileDialog). On 
Windows and OSX, it uses the native variants, but on X11 it uses a very 
outdated, ugly and hard to use thing bundled with Tk. With just a few 
lines executed by some Tk.eval('source myfixes.tcl'), I overwrite this 
dialog box with the one created by Schelte Bron:

http://wiki.tcl.tk/15897

For reference, here is myfixes.tcl:

lappend auto_path [file dirname [info script]]
if {[tk windowingsystem] == "x11" } {
package require fsdialog
interp alias {} tk_getOpenFile {} ttk::getOpenFile
interp alias {} tk_getSaveFile {} ttk::getSaveFile
interp alias {} tk_chooseDirectory {} ttk::chooseDirectory
}

Christian
--
https://mail.python.org/mailman/listinfo/python-list


Re: Module missing when embedding?

2013-12-17 Thread Garthy


Hi all,

On 12/12/13 18:03, Garthy wrote:
> I am attempting to embed Python 3.3.3 into an application.

...

> Any ideas about what I might be doing wrong? Anything I can try on the
> Python side or the C API side? My Python knowledge is a bit rusty so I
> may have missed something obvious on the Python side. If there are any
> resources online that show something similar to what I am doing, please
> share, and I'll do the legwork. More info available if needed- just ask.

Thanks to anyone who may have looked at this or the subsequent test(s) I 
posted. The problem has since been solved by loading modules through 
another method.


Cheers,
Garth
--
https://mail.python.org/mailman/listinfo/python-list


Re: Reading csv file

2013-12-17 Thread Peter Otten
Igor Korot wrote:

> Hi, ALL,
> Is there a better way to do that:
> 
> def Read_CSV_File(filename):
>   file = open(filename, "r")
>   reader = csv.DictReader(file)
>   line = 1
>   for row in reader:
>   if line < 6:
>  reader.next()
>  line++
> # process the CSV
> 
> Thank you.

You mean a way that works?

line++

is a syntax error in Python. If you fix that

line = 1
for row in reader:
if line < 6:
reader next()
line += 1

You are still reading the complete csv file. Assuming 

(1) the first row of the csv contains the column names
(2) you want to skip the first five rows of data

you'd have to write

reader = csv.Reader(file)
line = 0
while line < 5:
next(reader)
line += 1
for row in reader:
 # process csv row

A simpler alternative is to use itertools.islice():

for row in itertools.islice(reader, 5, None):
... # process csv row


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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Gene Heskett
On Monday 16 December 2013 20:30:47 Mark Lawrence did opine:

> On 17/12/2013 01:06, Roy Smith wrote:
> > In article ,
> > 
> >   Rick Johnson  wrote:
> >>Dovetails are nothing more than sadistic nostalgia --
> >>they give old men a "chubby" and young men a nightmare.
> > 
> > There is nothing more satisfying than cutting a set of dovetails by
> > hand and having them glide together like silk, the first time you
> > test-fit them, with no daylight visible anywhere.
> > 
> > Someday, mine will be like that :-)
> 
> I suspect that your manual skills are rather better than mine.  One of
> my favourite expressions, perhaps because I only ever heard my dad use
> it, is "like watching a cow handle a shotgun".

I'll plead to using a jig, and figure I have a good fit when I have to 
drive it together with a deadblow hammer.

Cheers, Gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page 

IBM's original motto:
Cogito ergo vendo; vendo ergo sum.
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
 law-abiding citizens.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Mark Lawrence

On 17/12/2013 07:58, [email protected] wrote:

 From all the toolkits, wxPython is probably the most
interesting. I used all versions from 2.0 (?) up to 2.8. Then
it has been decided to go unicode.

Let see in the wx interactive intepreter, it is only
the top of the iceberg. (Py27, wxPy294)


len('ሴЃ')

5

---

It has alos been decided to rework wxPython and create
wxPhoenix, unicode of course.

Impossible to put a Python string correctly in a widget
supposed to handle text. The design mistake is more
deeper than in wx29 (unicode).

I do not know the present status, but as the mistake
is a consequence of a unicode non understanding (plus
a little bit Python, plus a little bit wxWidgets), I doubt
that some improvement happened.

I attempted to explain unicode...

jmf



wxPython 3 (Phoenix) will be the first version that supports Python 3. 
This will obviously mean that for the first time, wxPython will be able 
to take full advantage of the superb PEP393 Flexible String 
Representation (FSR) which is available in Python 3.3+.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: Reading csv file

2013-12-17 Thread Bernd Nawothnig
On 2013-12-17, Igor Korot wrote:
> Hi, ALL,
> Is there a better way to do that:
>
> def Read_CSV_File(filename):
>   file = open(filename, "r")
>   reader = csv.DictReader(file)
>   line = 1
>   for row in reader:
>   if line < 6:
>  reader.next()
>  line++
> # process the CSV

#v+
def Read_CSV_File(filename):
with open(filename) as f:
for line,row in enumerate(csv.DictReader(f)):
if line >= 6:
# process the CSV
#v-




Bernd

-- 
no time toulouse
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reading csv file

2013-12-17 Thread Peter Otten
Peter Otten wrote:

> You are still reading the complete csv file. Assuming
> 
> (1) the first row of the csv contains the column names
> (2) you want to skip the first five rows of data
> 
> you'd have to write
> 
> reader = csv.Reader(file)

Sorry, I meant DictReader, not Reader.

> line = 0
> while line < 5:
> next(reader)
> line += 1
> for row in reader:
>  # process csv row
> 
> A simpler alternative is to use itertools.islice():
> 
> for row in itertools.islice(reader, 5, None):
> ... # process csv row


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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread wxjmfauth
Le mardi 17 décembre 2013 09:33:24 UTC+1, Mark Lawrence a écrit :
> On 17/12/2013 07:58, [email protected] wrote:
> 
> >  From all the toolkits, wxPython is probably the most
> 
> > interesting. I used all versions from 2.0 (?) up to 2.8. Then
> 
> > it has been decided to go unicode.
> 
> >
> 
> > Let see in the wx interactive intepreter, it is only
> 
> > the top of the iceberg. (Py27, wxPy294)
> 
> >
> 
>  len('ሴЃ')
> 
> > 5
> 
> >
> 
> > ---
> 
> >
> 
> > It has alos been decided to rework wxPython and create
> 
> > wxPhoenix, unicode of course.
> 
> >
> 
> > Impossible to put a Python string correctly in a widget
> 
> > supposed to handle text. The design mistake is more
> 
> > deeper than in wx29 (unicode).
> 
> >
> 
> > I do not know the present status, but as the mistake
> 
> > is a consequence of a unicode non understanding (plus
> 
> > a little bit Python, plus a little bit wxWidgets), I doubt
> 
> > that some improvement happened.
> 
> >
> 
> > I attempted to explain unicode...
> 
> >
> 
> > jmf
> 
> >
> 
> 
> 
> wxPython 3 (Phoenix) will be the first version that supports Python 3. 
> 
> This will obviously mean that for the first time, wxPython will be able 
> 
> to take full advantage of the superb PEP393 Flexible String 
> 
> Representation (FSR) which is available in Python 3.3+.
> 
> 
> 
> -- 
> 
> My fellow Pythonistas, ask not what our language can do for you, ask 
> 
> what you can do for our language.
> 
> 

I'm very happy for you.
You should at least serialized the tasks.

- wxPhoenix (wrapper of wxWidgets) is one thing
- wxPhoenix for Python3 / Python2 is something else
- Ditto for the FSR
- Ditto for "unicode"

For your information, that's at those times I decided
to have a look at the Qt derivatives, it was a very,
very good idea.

jmf
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Steven D'Aprano
On Mon, 16 Dec 2013 23:58:15 -0800, wxjmfauth wrote:

> From all the toolkits, wxPython is probably the most interesting. I used
> all versions from 2.0 (?) up to 2.8. Then it has been decided to go
> unicode.
> 
> Let see in the wx interactive intepreter, it is only the top of the
> iceberg. (Py27, wxPy294)
> 
 len('ሴЃ')
> 5


What does that have to do with wxPython? It looks like you're just mis-
using Python 2.7.

In Python 2.7, 'ሴЃ' is not a Unicode string, it is a byte string. The 
exact bytes you get are not well-defined but on many systems you may get 
a UTF-8 encoded byte string:


py> sys.version
'2.7.4 (default, Apr 18 2013, 17:48:59) \n[GCC 4.4.5]'
py> for b in 'ሴЃ':
... print hex(ord(b)), b
... 
0xe1 
0x88 �
0xb4 �
0xd0 
0x83 �


If you use a Unicode string instead:

py> for c in u'ሴЃ':
... print hex(ord(c)), c
... 
0x1234 ሴ
0x403 Ѓ

py> for b in u'ሴЃ'.encode('utf-8'):
... print hex(ord(b)), b
... 
0xe1 
0x88 �
0xb4 �
0xd0 
0x83 �



Even if it is true that wxPython cannot handle Unicode text, you haven't 
shown it here.



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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Christian Gollwitzer

Am 16.12.13 23:40, schrieb Chris Angelico:

On Tue, Dec 17, 2013 at 9:06 AM, Christian Gollwitzer  wrote:

Let the flame war begin!


I'll try to avoid flamage :)


:) So let's vigorously discuss about facts;)


But my rule of thumb with bash scripts is: If it exceeds a page or
two in length, it's probably time it got rewritten in an application
language. When a program is the size of gitk (>10KLOC), the benefits
relating to interactive use (as you mention below) become less
significant, and benefits relating to discoverability of the more
obscure features become more significant.


I do not know, whether bash has means to structure large programs, I 
suppose not. Tcl has (see below), and concerning discoverability, see 
also below.



It does command substitution (indeed the brackets [] do) and is one of the
key concepts of Tcl. mc is probably the command from msgcat which translates
i18n strings. Complaining about these basic things is like complaining about
indentation in Python.


Okay. Now, how am I to figure out where this command comes from? It's
not a host command (typing "mc" at the bash prompt comes up failure),
and it's not defined in the script itself (at least, I can't find
"proc mc" anywhere); is it a Tcl built-in? Where do I start looking?


Usually, I run the program in tkcon, an excellent interactive shell for 
Tcl. There you type "edit mc", and it shows you the definition, plus you 
can change it, send it back to the program and see how the modified 
program behaves now (without restarting it!) Under the hood, it executes 
commands like "info commands", "info args", "info body", which do the 
work. If it tells you that there is no such thing as "mc", it came from 
a compiled extension (a C procedure). Indeed, in this case you are out 
of luck, to my knowledge there is no info which extension loads that 
thing. But you could observe it before startup by putting up a command 
trace (some sort of callback) on "mc".


In the gitk case, mc comes from these lines:

package require msgcat
namespace import ::msgcat::mc

Now, be prepared: These lines do almost the same as

import msgcat
from msgcat import mc

would do in Python.

*What is this? I heard Tcl has no modules?* Don't listen to these 
people, today (well, namespaces exist since 8.0, 1997, packages date 
back further) you can use namespaces and packages to structure your 
programs and separate data. And because Tcl is highly introspective, you 
can ask about almost everything:


(src) 61 % namespace import
mc
(src) 62 % namespace origin mc
::msgcat::mc
(src) 63 %

(there is only one imported command in gitk, namespace import returns a 
list)



About globals: Yes "global" gives you a true global, but namespaces have 
namespace variables, which you should use instead. The awkward thing is 
that you need to import these (as the globals) into every proc which 
uses them, but by using an OO framework such as Snit, this burden is 
taken away from the programmer.


Still Python *has* advantages here. If there is a docstring, you can get 
help() about the unknown thing, it has a type() and in Tcl, the package 
author is responsible for wrapping the package content into a namespace. 
Something like "import Tkinter as Tk" is not possible in Tcl (well, you 
could rename the namespace, but if not carefully written, it may break 
the package).



* Interpreters in threads. There is no GIL, Tcl interpreters are thread safe
and more than one can coexist in a process and run concurrently. This is
accessible from script level through the Threads package.


Nice, though Python's threading and/or multiprocessing can do 90% of
what people want. Side point: What about Tk? Can you (a) run separate
GUI threads for separate windows? (b) manipulate widgets created by
another thread?


You can't run Tk more than once, that applies to almost every toolkit I 
know. But you can pass a message to the main thread to do it for you. 
This is quite easy; it looks like


thread::send -async $main [list doit $somedata]

You pass an arbitrary Tcl command which executes in the main thread as 
soon as it is idle. In fact, because of the embedded event loop in Tcl 
(not bound to Tk), you rarely need threads at all. Asynchronous I/O is 
very easy in Tcl (fileevent command).


That one question here with replicating nc to control a device would be 
a textbook example of fileevent usage in Tcl.



So there definitely are some advantages that Tcl has over Python. Put
against them is a superior object model, a large corpus of first-class
object types (dict, set, list, etc[1]), and a syntax that more clearly
differentiates names and strings without making variable references
look like a lot more than they are.


Lists and dicts exist in Tcl as first class objects. You just can't tell 
them apart from strings. Sets are in tcllib. Python is more strongly 
typed than Tcl in that respect, which can be an advantage. Specifically 
doing math is easier in 

Re: [newbie] trying socket as a replacement for nc

2013-12-17 Thread Jean-Michel Pichavant
> I'm a newbie in Python programming that is very much true, and
> contrary to what you seem to suggest I did my homework

At no point that was my intention, my apologies.
If you fixed the syntax error, you should be pretty close to the solution 
though.

JM


-- IMPORTANT NOTICE: 

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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Mark Lawrence

On 17/12/2013 09:29, Steven D'Aprano wrote:


Even if it is true that wxPython cannot handle Unicode text, you haven't
shown it here.



Personally I am convinced that wxPython can't handle unicode for the 
simple reason that it doesn't yet support Python 3 and we all know that 
Python 2 and unicode don't mix.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Mark Lawrence

On 17/12/2013 09:18, [email protected] wrote:

Le mardi 17 décembre 2013 09:33:24 UTC+1, Mark Lawrence a écrit :

On 17/12/2013 07:58, [email protected] wrote:


  From all the toolkits, wxPython is probably the most



interesting. I used all versions from 2.0 (?) up to 2.8. Then



it has been decided to go unicode.







Let see in the wx interactive intepreter, it is only



the top of the iceberg. (Py27, wxPy294)







len('ሴЃ')



5







---







It has alos been decided to rework wxPython and create



wxPhoenix, unicode of course.







Impossible to put a Python string correctly in a widget



supposed to handle text. The design mistake is more



deeper than in wx29 (unicode).







I do not know the present status, but as the mistake



is a consequence of a unicode non understanding (plus



a little bit Python, plus a little bit wxWidgets), I doubt



that some improvement happened.







I attempted to explain unicode...







jmf








wxPython 3 (Phoenix) will be the first version that supports Python 3.

This will obviously mean that for the first time, wxPython will be able

to take full advantage of the superb PEP393 Flexible String

Representation (FSR) which is available in Python 3.3+.



--

My fellow Pythonistas, ask not what our language can do for you, ask

what you can do for our language.




I'm very happy for you.
You should at least serialized the tasks.

- wxPhoenix (wrapper of wxWidgets) is one thing
- wxPhoenix for Python3 / Python2 is something else
- Ditto for the FSR
- Ditto for "unicode"

For your information, that's at those times I decided
to have a look at the Qt derivatives, it was a very,
very good idea.

jmf



I haven't the faintest idea what your words above are meant to mean. 
Your communication skills are clearly lacking, as you also still insist 
on sending us double spaced google crap.  Do you not understand the 
instructions here https://wiki.python.org/moin/GoogleGroupsPython ?


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: Reading csv file

2013-12-17 Thread Igor Korot
Hi, guys,

On Tue, Dec 17, 2013 at 12:55 AM, Peter Otten <[email protected]> wrote:
> Peter Otten wrote:
>
>> You are still reading the complete csv file. Assuming
>>
>> (1) the first row of the csv contains the column names
>> (2) you want to skip the first five rows of data

Looking at the Peter's reply I realized I missed very important piece:

The first row may or may not contain column names.
If it does not, the first row will just contain some text, i.e. "abc"
and the column names will be located on the row 6.

I know if does complicate things but I am deeply sorry.
The csv file is generated by some program run and I guess depending on
the switches passed to
that program it either creates the header in the csv (report name,
time slice it ran at, user it ran under
and some other info.
Or it can be run without such switch and then it generates a normal csv.

The report it generates is huge: it has about 30+ fields and I need to
read this report, parse it and
push accordingly to the database of mySQL.

Thank you for any suggestions and sorry for not posting complete task.

>>
>> you'd have to write
>>
>> reader = csv.Reader(file)
>
> Sorry, I meant DictReader, not Reader.
>
>> line = 0
>> while line < 5:
>> next(reader)
>> line += 1
>> for row in reader:
>>  # process csv row
>>
>> A simpler alternative is to use itertools.islice():
>>
>> for row in itertools.islice(reader, 5, None):
>> ... # process csv row
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Type of an object:

2013-12-17 Thread Gregory Ewing

Steven D'Aprano wrote:
I think I need to see an actual working demonstration, because as far as 
I can see, type(obj) returns obj.__class__.


Nope:

>>> class C(object):
...  def f(self):
...   return "Surprise!"
...  __class__ = property(f)
...
>>> c = C()
>>> type(c)

>>> c.__class__
'Surprise!'

It appears that type() bypasses the attribute access
mechanism and goes straight for the actual type.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Reading csv file

2013-12-17 Thread Peter Otten
Igor Korot wrote:

> Hi, guys,
> 
> On Tue, Dec 17, 2013 at 12:55 AM, Peter Otten <[email protected]> wrote:
>> Peter Otten wrote:
>>
>>> You are still reading the complete csv file. Assuming
>>>
>>> (1) the first row of the csv contains the column names
>>> (2) you want to skip the first five rows of data
> 
> Looking at the Peter's reply I realized I missed very important piece:
> 
> The first row may or may not contain column names.
> If it does not, the first row will just contain some text, i.e. "abc"
> and the column names will be located on the row 6.
> 
> I know if does complicate things but I am deeply sorry.
> The csv file is generated by some program run and I guess depending on
> the switches passed to
> that program it either creates the header in the csv (report name,
> time slice it ran at, user it ran under
> and some other info.
> Or it can be run without such switch and then it generates a normal csv.
> 
> The report it generates is huge: it has about 30+ fields and I need to
> read this report, parse it and
> push accordingly to the database of mySQL.
> 
> Thank you for any suggestions and sorry for not posting complete task.

Try the following (without the mock-ups of course):


$ cat csv_skip_header.py
import csv
import sys
from contextlib import contextmanager

filename = "ignored"

@contextmanager
def open(*args):
"mock-up, replace with open() built-in"
from StringIO import StringIO
lines = range(10)
if len(sys.argv) > 1 and sys.argv[1] == "--skip":
lines[0] = "skipped"
lines[6] = "field1-from-line6,field2-from-line6"
else:
lines[0] = "field1-from-line1,field2-from-line1"
yield StringIO("\r\n".join(map(str, lines)))

def is_arbitrary_text(fieldnames):
"mock-up, replace with the actual check"
return "skipped" in fieldnames

with open(filename, "rb") as f:
reader = csv.DictReader(f)
if is_arbitrary_text(reader.fieldnames):
for _ in range(5):
next(reader, None)
reader._fieldnames = None # underscore necessary,
  # fieldnames setter doesn't work
reader.fieldnames # used for its side-effect
for row in reader:
print row
$ python csv_skip_header.py 
{'field2-from-line1': None, 'field1-from-line1': '1'}
{'field2-from-line1': None, 'field1-from-line1': '2'}
{'field2-from-line1': None, 'field1-from-line1': '3'}
{'field2-from-line1': None, 'field1-from-line1': '4'}
{'field2-from-line1': None, 'field1-from-line1': '5'}
{'field2-from-line1': None, 'field1-from-line1': '6'}
{'field2-from-line1': None, 'field1-from-line1': '7'}
{'field2-from-line1': None, 'field1-from-line1': '8'}
{'field2-from-line1': None, 'field1-from-line1': '9'}
$ python csv_skip_header.py --skip
{'field1-from-line6': '7', 'field2-from-line6': None}
{'field1-from-line6': '8', 'field2-from-line6': None}
{'field1-from-line6': '9', 'field2-from-line6': None}

You may find the following a bit cleaner:

with open(filename, "rb") as f:
reader = csv.reader(f)
fieldnames = next(reader)
if is_arbitrary_text(fieldnames):
for _ in range(5):
next(reader, None)
fieldnames = None
reader = csv.DictReader(f, fieldnames=fieldnames)
for row in reader:
print row

Or you do the skipping on the file (only if the rows don't have embedded 
newlines).

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


Re: New to Python, Help to get script working?

2013-12-17 Thread Mark
I am sorry, using google groups i cant tell what you see...
Anyways, I guess i will just make lots of lines instead of long sentences?

How about this, the first person that can get this to work for me...
I will paypal them 20 dollars for helping me.
I just want to get this thing up and going.
Ive posted where i am having trouble and got 2 replies talking about spacing...
and not fixing any issues or giving advice.

Either that or somebody who thinks they might be able to help, can you plz 
reply?

Thanks again

Mark
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Oscar Benjamin
On 17 December 2013 00:39, rusi  wrote:
> On Tuesday, December 17, 2013 5:58:12 AM UTC+5:30, Ned Batchelder wrote:
>> On 12/16/13 3:32 PM, Wolfgang Keller wrote:
>> >>> And ever after that experience, I avoided all languages that were
>> >>> even remotely similar to C, such as C++, Java, C#, Javascript, PHP
>> >>> etc.

Thanks for sharing your experiences Wolfgang. I think many of my
students have a similar experience after learning C and it is
interesting to hear it from your perspective many years later.

I was also taught C as an undergrad but having already learned Java, C
and C++ before arriving at University I found the C course very easy
so my own experience is not representative. Many of the other students
at that time found the course too hard and just cheated on all the
assignments (I remember one students offering to fix/finish anyone's
assignment in exchange for a bottle of cider!).

>> >> I think that's disappointing, for two reasons. Firstly, C syntax isn't
>> >> that terrible.
>>
>> > It's not just the abysmally appalling, hideously horrifying syntax. At
>> > about everything about C is just *not* "made for human beings" imho.
>
>> I've never heard C syntax reviled quite so intensely.  What syntax do
>> you like, out of curiosity?
>
> I had a paper some years ago on why C is a horrible language *to teach with*
> http://www.the-magus.in/Publications/chor.pdf

Thanks for this Rusi, I just read it and it describes very well what I
think about our own C course. My choice quote from the beginning would
be "When the irrelevant becomes significant, the essentials become
obscured and incomprehensible."

(BTW is there any reason that the document is repeated twice in the same pdf?)

As a case in point one of my tutees asked for help with his C
assignment last week. I looked at his code and it was a complete mess.
I explained roughly what it should look like and he explained that he
had had so much trouble figuring out how to get the compiler to pass a
pair of strings into a function that he had given up and used global
variables instead. He's just not ready yet to get an intuitive
understanding of where to put the asterisks in order to make it work -
and as you point out in that paper the rules for where the asterisks
go are hopelessly inconsistent.

A couple of weeks before, another of my tutees brought their
assignment which was about dynamic memory allocation (~7 weeks into
her first programming course). She had just written something like
   char *x = (char*)malloc(31*sizeof(char));
for a global x at the top of the file. So the message about dynamic
memory allocation was entirely lost in the details of C: "dynamic
memory allocation means using malloc".

These types of problems are compounded by the fact that the current C
course uses automated marking so a program that produces the correct
output gets full marks even if it is terribly written and the student
entirely misses the point - another thing about this course that
definitely needs to change.

> I believe people did not get then (and still dont) that bad for
> - beginner education (CS101)
> - intermediate -- compilers, OS, DBMS etc
> - professional software engineering
>
> are all almost completely unrelated

Agreed.


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Steven D'Aprano
On Tue, 17 Dec 2013 09:39:06 +, Mark Lawrence wrote:

> Personally I am convinced that wxPython can't handle unicode for the
> simple reason that it doesn't yet support Python 3 and we all know that
> Python 2 and unicode don't mix.

I don't think this is right. The Unicode support in Python 2 isn't as 
good as in Python 3, but it is still pretty good. You just have to 
remember to use the u prefix on your strings.

If it is true that wxPython cannot handle Unicode -- and I see no 
evidence that this is correct -- then it is due to the underlying wx* 
library, not Python 2.


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


Re: [newbie] Saving binaries in a specific way

2013-12-17 Thread Oscar Benjamin
On 16 December 2013 22:19, Djoser  wrote:
> Hi all,

Hi Djoser,

> I am new to this forum and also to Python, but I'm trying hard to understand 
> it  better.
> I need to create a binary file, but the first 4 lines must be in 
> signed-Integer16 and all the others in signed-Integer32. I have a program 
> that does that with Matlab and other with Mathematica, but I'm converting all 
> for Python.

If you're coming from Matlab/Mathematica to Python you will likely
want to use the numpy library. This provides an array type that is
similar to Matlab arrays.

> I tried first to convert the number to binary using 'bin(number'), than I 
> removed the '0b' and converted to 'Int16' or 'Int32', but with this approach 
> I can't save a binary file using 'bytearray(').

Using numpy you can do this as follows:

import numpy as np

# Create arrays with the appropriate numeric types
first_numbers = np.array([12, -2, 10, -1], np.int16)
other_numbers = np.array([123, 123, 432, 543, 654, 654], np.int32)

# Output direct to binary file
with open('outputfile.bin', 'wb') as fout:
first_numbers.tofile(fout)
other_numbers.tofile(fout)

# Read back in from binary file
with open('outputfile.bin', 'rb') as fin:
first_numbers_read = np.fromfile(fin, np.int16, count=4)
other_numbers_read = np.fromfile(fin, np.int32)

# Print the data that we read back to check it's right.
print(first_numbers_read)
print(other_numbers_read)


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Steven D'Aprano
On Tue, 17 Dec 2013 11:12:07 +, Oscar Benjamin wrote:

> These types of problems are compounded by the fact that the current C
> course uses automated marking so a program that produces the correct
> output gets full marks even if it is terribly written and the student
> entirely misses the point

This suggests that even the lecturers can't read C, and so have got one 
of their post-grad students to write an automated tester so they don't 
have to.

Only-half-joking-ly y'rs, 


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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread wxjmfauth
Le mardi 17 décembre 2013 10:29:28 UTC+1, Steven D'Aprano a écrit :
> On Mon, 16 Dec 2013 23:58:15 -0800, wxjmfauth wrote:
> 
> 
> 
> > From all the toolkits, wxPython is probably the most interesting. I used
> 
> > all versions from 2.0 (?) up to 2.8. Then it has been decided to go
> 
> > unicode.
> 
> > 
> 
> > Let see in the wx interactive intepreter, it is only the top of the
> 
> > iceberg. (Py27, wxPy294)
> 
> > 
> 
>  len('ሴЃ')
> 
> > 5
> 
> 
> 
> 
> 
> What does that have to do with wxPython? It looks like you're just mis-
> 
> using Python 2.7.
> 
> 
> 
> In Python 2.7, 'ሴЃ' is not a Unicode string, it is a byte string. The 
> 
> exact bytes you get are not well-defined but on many systems you may get 
> 
> a UTF-8 encoded byte string:
> 
> 
> 
> 
> 
> py> sys.version
> 
> '2.7.4 (default, Apr 18 2013, 17:48:59) \n[GCC 4.4.5]'
> 
> py> for b in 'ሴЃ':
> 
> ... print hex(ord(b)), b
> 
> ... 
> 
> 0xe1 
> 
> 0x88 �
> 
> 0xb4 �
> 
> 0xd0 
> 
> 0x83 �
> 
> 
> 
> 
> 
> If you use a Unicode string instead:
> 
> 
> 
> py> for c in u'ሴЃ':
> 
> ... print hex(ord(c)), c
> 
> ... 
> 
> 0x1234 ሴ
> 
> 0x403 Ѓ
> 
> 
> 
> py> for b in u'ሴЃ'.encode('utf-8'):
> 
> ... print hex(ord(b)), b
> 
> ... 
> 
> 0xe1 
> 
> 0x88 �
> 
> 0xb4 �
> 
> 0xd0 
> 
> 0x83 �
> 
> 
> 
> 
> 
> 
> 
> Even if it is true that wxPython cannot handle Unicode text, you haven't 
> 
> shown it here.
> 
> 
> 
> 
> 
> 
Quich answer.

That's PyShell, the wxPy interpreter.

You are right in pointing all this missmatch: byte string,
unicode, utf-8, mixing a "unicode" tool kit wiht a non
unicode native engine, plus plenty of related things, ...

You may be not aware. I contributed to wxPython from
practically 2.0, 2.1. 2.2 during 6, 7, 8 yeaurs, testing,
reporting about/with all versions, then I gave up.

---

Yout quote.
"Even if it is true that wxPython cannot handle Unicode text..."

It's a confusing vision and that's not correct. It's a little bit
more complicate than this.

jmf


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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Robert Kern

On 2013-12-17 11:13, Steven D'Aprano wrote:

On Tue, 17 Dec 2013 09:39:06 +, Mark Lawrence wrote:


Personally I am convinced that wxPython can't handle unicode for the
simple reason that it doesn't yet support Python 3 and we all know that
Python 2 and unicode don't mix.


I don't think this is right. The Unicode support in Python 2 isn't as
good as in Python 3, but it is still pretty good. You just have to
remember to use the u prefix on your strings.

If it is true that wxPython cannot handle Unicode -- and I see no
evidence that this is correct --


It most certainly is not. wxPython has handled Unicode (via `unicode` strings) 
for many, many years now.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Chris Angelico
On Tue, Dec 17, 2013 at 8:33 PM, Christian Gollwitzer  wrote:
> Am 16.12.13 23:40, schrieb Chris Angelico:
>> But my rule of thumb with bash scripts is: If it exceeds a page or
>> two in length, it's probably time it got rewritten in an application
>> language. When a program is the size of gitk (>10KLOC), the benefits
>> relating to interactive use (as you mention below) become less
>> significant, and benefits relating to discoverability of the more
>> obscure features become more significant.
>
> I do not know, whether bash has means to structure large programs, I suppose
> not. Tcl has (see below), and concerning discoverability, see also below.

You can create functions, which then effectively become new commands.
You can source (the . command) another file, which mostly is a
#include style of thing. But mainly, a bash script is doing exactly
what would happen at the interactive shell (modulo environment
differences - your interactive shell might well have a different $PATH
or something, but command execution still follows the same rules). If
I look at a bash script and see it execute "bc", I can type "man bc"
and have a reasonable chance of it being the same thing.

> In the gitk case, mc comes from these lines:
>
> package require msgcat
> namespace import ::msgcat::mc
>
> Now, be prepared: These lines do almost the same as
>
> import msgcat
> from msgcat import mc
>
> would do in Python.

Okay. Now that you've told me that, I can find those lines... down the
very bottom of the script. The first thing I did when trying to figure
this out was to go to the top of the file and search for "mc", and I
didn't find a definition.

In Python, it's conventional to put imports at the top, so this would
have worked. (Unless there's a "from x import *", but this is
precisely why that's frowned upon.) Is the convention different in
Tcl, or is gitk just laid out unhelpfully?

> You can't run Tk more than once, that applies to almost every toolkit I
> know. But you can pass a message to the main thread to do it for you. This
> is quite easy; it looks like
>
> thread::send -async $main [list doit $somedata]

Everything I ever did on OS/2 allowed GUI operations from multiple
threads. The C APIs, I think, were restricted to manipulating each
widget from the thread that created it (or at least, you could confuse
yourself thoroughly if you didn't; I always just stuck to "this
window, this thread"); VX-REXX allowed any thread to manipulate any
object belonging to that process. If you send a message to a widget,
its thread will handle it (and yours will block until you get a
response - or you can post a message, which doesn't block); this
functions the same whether it's a thread in your process or one in
another process.

> You pass an arbitrary Tcl command which executes in the main thread as soon
> as it is idle. In fact, because of the embedded event loop in Tcl (not bound
> to Tk), you rarely need threads at all. Asynchronous I/O is very easy in Tcl
> (fileevent command).

I learned to love async processing a couple of years ago with Pike.
You just return a negative number from main(), which normally has no
meaning, and it goes into a back-end event loop. (And there are other
ways to invoke the back-end.) That can then handle callbacks from
files/sockets, clock-based timeouts ("call this function in X
seconds"), GUI events, pretty much everything (except signals - they
interrupt everything else, as they should). It takes a bit of getting
your head around, if you're used to thread-based programming (as I had
been for a decade or so), but it's so convenient.

>> So there definitely are some advantages that Tcl has over Python. Put
>> against them is a superior object model, a large corpus of first-class
>> object types (dict, set, list, etc[1]), and a syntax that more clearly
>> differentiates names and strings without making variable references
>> look like a lot more than they are.

>> [1] What is an etc() in Python?
>
> Is this a quizzy question? I have no idea.

I mentioned four of Python's fundamental types: the dict, the set, the
list, and the etc. :)

> Lists and dicts exist in Tcl as first class objects. You just can't tell
> them apart from strings. Sets are in tcllib. Python is more strongly typed
> than Tcl in that respect, which can be an advantage. Specifically doing math
> is easier in an evaluation based syntax than in a command based syntax, this
> sometimes sucks in Tcl.

Having grown up with REXX, I completely understand the concept of
"everything is a string" (though REXX does have compound variables,
which aren't quite lists, aren't quite dicts, and aren't quite sets,
and definitely aren't quite multidimensional anything, but are their
own beast with unique semantics); and having since met Python and Pike
and other such languages, I prefer object semantics. The only
first-class type in REXX is the string; a compound variable is a
different sort of name, not a different

Fwd: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Igor Korot
On Tue, Dec 17, 2013 at 01:36:43AM -0800, Igor Korot wrote:
> Hi, guys,
>
> On Tue, Dec 17, 2013 at 1:29 AM, Steven D'Aprano  wrote:
> > On Mon, 16 Dec 2013 23:58:15 -0800, wxjmfauth wrote:
>
 I think you are doing exactly what Steven D'Aprano said:

 Please compare:

 "abc" vs 'abc'

 from wxPython point of view.
 Also remember that wxPython is a wrapper around C++ library where
 string are usually
 defined with double quotes.

 Thank you.

> >
> >> From all the toolkits, wxPython is probably the most interesting. I used
> >> all versions from 2.0 (?) up to 2.8. Then it has been decided to go
> >> unicode.
> >>
> >> Let see in the wx interactive intepreter, it is only the top of the
> >> iceberg. (Py27, wxPy294)
> >>
> > len('ሴЃ')
> >> 5
> >
> >
> > What does that have to do with wxPython? It looks like you're just mis-
> > using Python 2.7.
> >
> > In Python 2.7, 'ሴЃ' is not a Unicode string, it is a byte string. The
> > exact bytes you get are not well-defined but on many systems you may get
> > a UTF-8 encoded byte string:
> >
> >
> > py> sys.version
> > '2.7.4 (default, Apr 18 2013, 17:48:59) \n[GCC 4.4.5]'
> > py> for b in 'ሴЃ':
> > ... print hex(ord(b)), b
> > ...
> > 0xe1
> > 0x88 �
> > 0xb4 �
> > 0xd0
> > 0x83 �
> >
> >
> > If you use a Unicode string instead:
> >
> > py> for c in u'ሴЃ':
> > ... print hex(ord(c)), c
> > ...
> > 0x1234 ሴ
> > 0x403 Ѓ
> >
> > py> for b in u'ሴЃ'.encode('utf-8'):
> > ... print hex(ord(b)), b
> > ...
> > 0xe1
> > 0x88 �
> > 0xb4 �
> > 0xd0
> > 0x83 �
> >
> >
> >
> > Even if it is true that wxPython cannot handle Unicode text, you haven't
> > shown it here.
> >
> >
> >
> > --
> > Steven
> > --
> > https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Mark Lawrence

On 17/12/2013 11:13, Steven D'Aprano wrote:

On Tue, 17 Dec 2013 09:39:06 +, Mark Lawrence wrote:


Personally I am convinced that wxPython can't handle unicode for the
simple reason that it doesn't yet support Python 3 and we all know that
Python 2 and unicode don't mix.


I don't think this is right. The Unicode support in Python 2 isn't as
good as in Python 3, but it is still pretty good. You just have to
remember to use the u prefix on your strings.

If it is true that wxPython cannot handle Unicode -- and I see no
evidence that this is correct -- then it is due to the underlying wx*
library, not Python 2.




Sorry folks, I'd been up all night and messed that up completely.  I 
meant to say "Personally I am convinced that *IF* wxPython can't handle 
unicode *IT WILL BE* for the simple reason that it doesn't yet support 
Python 3 and we all know that Python 2 and unicode don't mix".  It would 
have been better still if I'd added right at the end "particularly 
well", with this being the impression I get from the bug tracker, with 
far fewer bugs being raised against Python 3 unicode that I'm aware of 
rather than Python 2.  I'm now crossing my fingers and legs and hoping 
that my impression is correct.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


patch for making distutils cross compile on win32

2013-12-17 Thread Robin Becker
I have struggled to get Python-3.3.3 distutils to cross compile win-amd64 on 
win32. For the specific command (bdist_wininst) I am using the patch below seems 
to fix things so I can build amd64 binaries on win32. The code seems a bit 
schizophrenic about whether this is supposed to work, but without the patch it 
certainly doesn't.


*** \python33\lib\distutils\command\bdist_wininst.pyWed Aug 01 10:05:14 2012
--- distutils\command\bdist_wininst.py  Tue Dec 17 13:14:02 2013
***
*** 72,88 


  def finalize_options(self):
- self.set_undefined_options('bdist', ('skip_build', 'skip_build'))
-
  if self.bdist_dir is None:
! if self.skip_build and self.plat_name:
  # If build is skipped and plat_name is overridden, bdist will
  # not see the correct 'plat_name' - so set that up manually.
! bdist = self.distribution.get_command_obj('bdist')
! bdist.plat_name = self.plat_name
  # next the command will be initialized using that name
  bdist_base = self.get_finalized_command('bdist').bdist_base
  self.bdist_dir = os.path.join(bdist_base, 'wininst')

  if not self.target_version:
  self.target_version = ""
--- 72,89 


  def finalize_options(self):
  if self.bdist_dir is None:
! if self.plat_name:
  # If build is skipped and plat_name is overridden, bdist will
  # not see the correct 'plat_name' - so set that up manually.
! self.distribution.get_command_obj('build').plat_name = 
self.plat_name
! self.distribution.get_command_obj('build_py').plat_name = 
self.plat_name
! self.distribution.get_command_obj('build_ext').plat_name = 
self.plat_name
! self.distribution.get_command_obj('bdist').plat_name = 
self.plat_name

  # next the command will be initialized using that name
  bdist_base = self.get_finalized_command('bdist').bdist_base
  self.bdist_dir = os.path.join(bdist_base, 'wininst')
+ self.set_undefined_options('bdist', ('skip_build', 'skip_build'))

  if not self.target_version:
  self.target_version = ""
*** \python33\lib\distutils\command\build_ext.pySun Oct 27 17:02:50 2013
--- distutils\command\build_ext.py  Tue Dec 17 12:48:51 2013
***
*** 218,224 
  new_lib = os.path.join(sys.exec_prefix, 'PCbuild')
  if suffix:
  new_lib = os.path.join(new_lib, suffix)
! self.library_dirs.append(new_lib)

  elif MSVC_VERSION == 8:
  self.library_dirs.append(os.path.join(sys.exec_prefix,
--- 218,226 
  new_lib = os.path.join(sys.exec_prefix, 'PCbuild')
  if suffix:
  new_lib = os.path.join(new_lib, suffix)
! self.library_dirs.insert(0,new_lib)
! else:
! self.library_dirs.append(new_lib)

  elif MSVC_VERSION == 8:
  self.library_dirs.append(os.path.join(sys.exec_prefix,
--
Robin Becker

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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread wxjmfauth
Le mardi 17 décembre 2013 14:03:03 UTC+1, Robert Kern a écrit :
> On 2013-12-17 11:13, Steven D'Aprano wrote:
> 
> > On Tue, 17 Dec 2013 09:39:06 +, Mark Lawrence wrote:
> 
> >
> 
> >> Personally I am convinced that wxPython can't handle unicode for the
> 
> >> simple reason that it doesn't yet support Python 3 and we all know that
> 
> >> Python 2 and unicode don't mix.
> 
> >
> 
> > I don't think this is right. The Unicode support in Python 2 isn't as
> 
> > good as in Python 3, but it is still pretty good. You just have to
> 
> > remember to use the u prefix on your strings.
> 
> >
> 
> > If it is true that wxPython cannot handle Unicode -- and I see no
> 
> > evidence that this is correct --
> 
> 
> 
> It most certainly is not. wxPython has handled Unicode (via `unicode` 
> strings) 
> 
> for many, many years now.
> 
> 
> 
> -- 
> 
> Robert Kern
> 

---

Correct.

Output of my last interactive interpreter I wrote with
that toolkit.

Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on 
win32
>>> 
psi runs psizero.py...
...psizero has been executed
>>> '€'
€
>>> print('€')
€
>>> u'€'
?
>>> print(u'€')
?
>>> u'\u20ac'
€
>>> print(u'\u20ac')
€
>>> 

And if I cut/copy/paste something like this:
'ሴ䕧'
into that interpreter, it behaves like this ('??'):

>>> u'asdf'
asdf
>>> '??'
??
>>> 999
999
>>> "éléphant"
éléphant
>>> 'éléphant'
éléphant
>>> 


jmf
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Chris Angelico
On Tue, Dec 17, 2013 at 10:12 PM, Oscar Benjamin
 wrote:
> I was also taught C as an undergrad but having already learned Java, C
> and C++ before arriving at University I found the C course very easy
> so my own experience is not representative. Many of the other students
> at that time found the course too hard and just cheated on all the
> assignments (I remember one students offering to fix/finish anyone's
> assignment in exchange for a bottle of cider!).

Student cheats on assignment and gets, in effect, a fraudulent
certification. (Piece of paper claims competence, competence doesn't
exist.) Graduating student shows certification to employer. Employer
hires ex-student, because employer doesn't know good code from bad
(hence hiring someone). Ex-student writes a pile of junk, then leaves
for a better opportunity. Real programmer is hired, or seconded from
another project, to fix a few small issues in ex-student's code.
Lunatic asylum gains another patient.

It's all too common. I'd like to tell people that they're only
cheating themselves, but the trouble is, they're cheating other people
a lot more.

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


Bootstrapping a test environment

2013-12-17 Thread Burak Arslan
Hello list,

I decided to set up a portable Jenkins environment for an open source
project I'm working on.

After a couple of hours of tinkering, I ended up with this:

https://github.com/arskom/spyne/blob/05f7a08489e6dc04a3b5659eb325390bea13b2ff/run_tests.sh
(it should have been a Makefile)

This worked just fine.

Next, I wanted to integrate other Python implementations to this setup,
but none really worked so far. Jython-2.7-beta installs fine but seems
to have problems fetching stuff from the internet. I couldn't get
IronPython to compile under mono at all. I couldn't look at PyPy deeply
but resource requirements for building it seem scary...

Here's the latest version of that script:
https://github.com/arskom/spyne/blob/master/run_tests.sh

Note that there's nothing project-specific there except the --source and
--omit parameters to coverage.

Here's the script in action: https://spyne.ci.cloudbees.com/. Btw, Kudos
to cool folks at cloudbees for supporting FOSS, It's been rock solid so
far. They got unlimited parallel executors, no less :)

So, could people who've done similar things share their experience? How
do you suggest I should proceed here? Do you have a working ipy/mono
version combination that works? Is there a similar build script for PyPy
somewhere?

Pull requests are very much welcome :)

Best regards,
Burak

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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Cousin Stanley



Rick Johnson  wrote:

 Dovetails are nothing more than sadistic nostalgia --
 they give old men a "chubby" and young men a nightmare.



There is nothing more satisfying than cutting a set of dovetails by hand
and having them glide together like silk, the first time you test-fit
them, with no daylight visible anywhere.


  This dove-tailer understands Rapid Application Development 

 http://woodwork.ars-informatica.ca/tool.php?art=dovetail_video
 Frank Klausz's three-minute dovetails using a bow saw

--
Stanley C. Kitching
Human Being
Phoenix, Arizona 



---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com

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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread wxjmfauth
Addendum.

I should say, I had also a lot of fun in writing my own
"styling engine".

Because when one has to deal with a language, which does
not recognize its own keywords...

>>> 1and 444
444
>>>

tokenize.py could have been a solution, but it's really
too slow.

jmf
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Type of an object:

2013-12-17 Thread Ethan Furman

On 12/17/2013 02:35 AM, Gregory Ewing wrote:

Steven D'Aprano wrote:

I think I need to see an actual working demonstration, because as far as I can 
see, type(obj) returns obj.__class__.


Nope:


class C(object):

...  def f(self):
...   return "Surprise!"
...  __class__ = property(f)
...

c = C()
type(c)



c.__class__

'Surprise!'


I believe the proxying info comes into play with __class__.__name__:

--> class Test:
...   pass
...

--> t = Test()

--> type(t)


--> t.__class__


--> t.__class__.__name__
'Test'

--> t.__class__.__name__ = 'some_proxy'

--> t.__class__.__name__
'some_proxy'

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Mark Lawrence

On 17/12/2013 14:43, [email protected] wrote:

Addendum.

I should say, I had also a lot of fun in writing my own
"styling engine".

Because when one has to deal with a language, which does
not recognize its own keywords...


1and 444

444




tokenize.py could have been a solution, but it's really
too slow.

jmf



To what, where is your context, my crystal ball is broken again?

--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Neil Cerutti
On 2013-12-17, Steven D'Aprano
 wrote:
> I would really like to see good quality statistics about bugs
> per program written in different languages. I expect that, for
> all we like to make fun of COBOL, it probably has few bugs per
> unit-of-useful-work-done than the equivalent written in C.

I can't think of a reference, but I to recall that
bugs-per-line-of-code is nearly constant; it is not language
dependent. So, unscientifically, the more work you can get done
in a line of code, then the fewer bugs you'll have per amount of
work done.

-- 
Neil Cerutti

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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Roy Smith
In article ,
 Neil Cerutti  wrote:

> On 2013-12-17, Steven D'Aprano
>  wrote:
> > I would really like to see good quality statistics about bugs
> > per program written in different languages. I expect that, for
> > all we like to make fun of COBOL, it probably has few bugs per
> > unit-of-useful-work-done than the equivalent written in C.

Well, there was that little Y2K thing...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Wolfgang Keller
> Python is sooo slow when it waits for the human.

With Windows systems, I waste something like 90% of my work time waiting
for that system to stop "Not Responding".

And no, it's not a matter of hardware.

Sincerely,

Wolfgang
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Wolfgang Keller
> For example Firefox implements its entire GUI in
> Javascript using XML GUI definitions.

Which has made Firefox essentially unusable because it will fall into
koma ("Not Responding") for minutes upon almost each and every
mouseclick. Unfortunately I don't know any significantly better
alternatives.

> And all modern web apps are a combination of many languages and
> domains, most of which are "compiled" in the traditional sense.

"Web apps" are the most efficient way I know of to make users who have
to get actual work done as inefficient as possible. It's especially an
extremely effective way, together with Firefox's "responsiveness", to
make any operating system as obscenely unusable as Windows.
 
Sincerely,

Wolfgang
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Mark Lawrence

On 17/12/2013 14:54, Roy Smith wrote:

In article ,
  Neil Cerutti  wrote:


On 2013-12-17, Steven D'Aprano
 wrote:

I would really like to see good quality statistics about bugs
per program written in different languages. I expect that, for
all we like to make fun of COBOL, it probably has few bugs per
unit-of-useful-work-done than the equivalent written in C.


Well, there was that little Y2K thing...



Design assumption made 30 to 40 years earlier "It'll only have to be in 
the field for six months" :)


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Wolfgang Keller
> The other thing, specially if you would make a customer project, I
> don't know how to pack the app written in python in an installer.

If you want your application to be actually user-friendly, you make it
available as an installer-less zip archive. It works with Python
applications, no matter whether they use PyGTK, wxPython or PyQt.

> Perhaps I am wrong, and you could give me in exchange an advise ?!

Python is probably the "best" language for application implementation in
general. Anything that would really need to be faster than python
itself allows can easily be implemented in "compiled" Python à la Pyrex
et al.

> I also believe in performance. An application written in C++, can be 
> compiled easily on the target platform (like on windows systems) with 
> it's native compiler.
> How would it be with wxPython ?!

It isn't an issue.

With that pathological non-operating system Microsoft (Not Responding),
as soon as your application has to do any I/O, or if there's any other
process (virus scanner, file system indexer) running that does I/O,
any computer will be unusable for productive work anyway.

On an actual operating system, the attitude of the developers (do they
actually care or just don't give a darn) is *the* critical issue for
end-user productivity. If a developer makes a statement such as
of "just get a faster computer" or "just get more RAM", then (s)he
probably doesn't give darn. C++ applications, just like Java
applications, tend to leak horrible amounts of memory these days, just
because the vendors/developers don't care.

Sincerely,

Wolfgang
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Wolfgang Keller
> Please check JYTHON and those ready-for-novice GUI tools in java.

All Java GUI frameworks I know of are ridiculous garbage.

Not only that Java per se is obscenely fat (and unresponsive), but the
GUI frameworks leak like bottomless barrels and the look and feel is so
hideous that I would say from personal experience with numerous Java
applications that there is little that's worse for user productivity
than a Java application running on Windows. Well, a "web application"
might top it.

Sincerely,

Wolfgang
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Type of an object:

2013-12-17 Thread Steven D'Aprano
On Tue, 17 Dec 2013 23:35:10 +1300, Gregory Ewing wrote:

> Steven D'Aprano wrote:
>> I think I need to see an actual working demonstration, because as far
>> as I can see, type(obj) returns obj.__class__.
> 
> Nope:
> 
>  >>> class C(object):
> ...  def f(self):
> ...   return "Surprise!"
> ...  __class__ = property(f)
> ...
>  >>> c = C()
>  >>> type(c)
> 
>  >>> c.__class__
> 'Surprise!'


Well, that is a surprise, but I don't think that is intended behaviour. I 
think that's something which only works by accident. The intention is 
that __class__ returns the instance's type, not arbitrary values. If you 
try to set it to a non-class on the instance, it fails:


py> class D(object):
... pass
...
py> d = D()
py> d.__class__ = property(lambda self: 'Surprise!')
Traceback (most recent call last):
  File "", line 1, in 
TypeError: __class__ must be set to a class, not 'property' object


Same when you try to set it on the class object itself:

py> D.__class__ = property(lambda self: 'Surprise!')
Traceback (most recent call last):
  File "", line 1, in 
TypeError: __class__ must be set to a class, not 'property' object


So my guess is that the fact that your code works at all is an accident.

I can demonstrate that changing the __class__ of an instance causes 
type(obj) to return a different value, and also to dynamically change the 
behaviour of the object:


py> class Spam(object):
... def method(self):
... return "spam"
...
py> class Ham(object):
... def method(self):
... return "ham"
...
py> ham = Ham()
py> ham.method()
'ham'
py> ham.__class__ = Spam
py> ham.method()
'spam'
py> type(ham)



So this is a case where type(obj) returns obj.__class__ rather than it's 
internal type field. That's the point I was trying to make: type(obj) may 
return obj's internal type field, but if you set obj.__class__, type(obj) 
will then return the new class, not the internal one.


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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Steven D'Aprano
On Tue, 17 Dec 2013 09:54:41 -0500, Roy Smith wrote:

> In article ,
>  Neil Cerutti  wrote:
> 
>> On 2013-12-17, Steven D'Aprano
>>  wrote:
>> > I would really like to see good quality statistics about bugs per
>> > program written in different languages. I expect that, for all we
>> > like to make fun of COBOL, it probably has few bugs per
>> > unit-of-useful-work-done than the equivalent written in C.
> 
> Well, there was that little Y2K thing...

Oh come on, how were people in the 1990s supposed to predict that they 
would be followed by the year 2000???

That's a good point, but that wasn't a language issue, it was a program 
design issue. Back in the 70s and 80s, when saving two digits per date 
field seemed to be a sensible thing to do, people simply didn't imagine 
that their programs would still be used in the year 1999[1]. That's not 
the same sort of bug as (say) C buffer overflows, or SQL code injection 
attacks. It's not like the COBOL language defined dates as having only 
two digits.




[1] What gets me is that even in the year 1999, there were still 
programmers writing code that assumed two-digit years. I have it on good 
authority from somebody working as an external consultant for a bank in 
1999 that he spent most of 1998 and 1999 fixing *brand new code* written 
by the bank's own staff. You'd think that having lived through that 
experience would have shaken his belief that private enterprise does 
everything better, and the bigger the corporation the better they do it, 
but apparently not. Go figure.


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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Wolfgang Keller
> > It's not just the abysmally appalling, hideously horrifying syntax.
> > At about everything about C is just *not* "made for human beings"
> > imho.
> 
> I've never heard C syntax reviled quite so intensely.  What syntax do 
> you like, out of curiosity?

Pascal, Python, if written by someone who uses semantic identifiers and
avoids to use C(++)/Java-isms. I've seen Eiffel as well (without
understanding it) and it didn't look ridiculous to me.

In short, syntax that contains the strict minimum of "special"
characters (delimiting lists etc. with brackets is ok to me), and
almost exclusively human readable words. Although, if you push it to the
extreme; Applescript is nice to read, but much less nice to write
imho... :-/

C, C++, Java, Javascript, PHP, Perl etc., however, are just
unspeakable .



BTW; Yes, I do *hate* those C(++)-isms (or Java-isms) that have started
to sneak into Python in the past ~10 years. Using e.g. == for
comparisons is just braindead. Use := for assignments instead, because
that's mathematical syntax. And that "@" for decorators is, well, who
proposed it? I'd like to cut off all his fingers with a bolt cutter.
The same for people who use augmented assignments, "syntax shortcuts"
or abbrvtd idtfrs. Ship them all to Fukushima, one way, no return
ticket. Learn to touch-type, get an editor with decent syntax
completion or just stop wreaking havoc to the world economy with your
laziness. Code is read a hundred times more often than it is typed.



Sincerely,

Wolfgang 
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Question RE urllib

2013-12-17 Thread Jeff James
So I'm using the following script to check our sites to make sure they are
all up and some of them are reporting they are "down" when, in fact, they
are actually up.   These sites do not require a logon in order for the home
page to come up.  Could this be due to some port being blocked internally ?
 Only one of the sites reporting as down is "https" but all are internal
sites.  Is there some other component I should be including in the script ?
 There are about 30 or 40 sites that I have listed in all.  I just use
those in the following script as examples.   Thanks

import urllib

sites = ["http://www.amazon.com/";, "https://internalsite.com/intranet.html";,
etc.]

for site in sites:
try:
urllib.urlopen(site)
print site + " "
except Exception, e:
print site + " is down"
-- 
https://mail.python.org/mailman/listinfo/python-list


I've never used urllib, although I've done a fair amount of network
programming at lower levels.

Are you sure the report of "down" isn't simply a time out due to the server
being busier than you expect when you hit it?

-Bill

After adding the line suggested by Larry, I was able to determine that the
URLs reporting as "down" were actually sites requiring authentication in
order to provide site content, so adding that line to the handler was at
least enlightening in that respect.  Thanks Larry.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Wolfgang Keller
> On Sun, Dec 15, 2013 at 4:33 PM, Wolfgang Keller 
> wrote:
> > And besides, again, a commercially licensed PyQt itself isn't *that*
> > expensive.
> 
> > The cost of a commercial PyQt license for a single developer is £350
> > (GBP). You may pay in either US Dollars, Euros or GBP.

I didn't write the second paragraph. Please learn to quote, thanks.
 
> (£420 incl. VAT for UK and select EU entities)

For a commercial developer that doesn't appear much to me. I know Qt
applications that cost ~100.000 EUR per seat. Others are so valuable
that they simply aren't sold at all.

Wingware since recently uses PyQt and their prices don't seem to have
skyrocketed since the migration from PyGTK.

> > one [license] per developer
> 
> For some people, it might be a lot.  Why waste money on something,
> that has an almost-identical free-for-everyone version? (which also is
> easier to install, BTW)

Because PySide is *far* from identical.
 
> > PyQt does not include Qt itself. You must also obtain an
> > appropriately licensed copy (either the commercial version from
> > Digia or the LGPL version from the Qt Project).

Thanks again for learning to quote correctly. I did not write this
paragraph.
 
> So, you have four options:

If you need something that's actually supported, Pyside (currently)
doesn't look like a credible option to me.

And for "home users", education etc., the GPL version of PyQt seems
perfect to me.

Sincerely,

Wolfgang
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Mark Lawrence

On 17/12/2013 15:24, Steven D'Aprano wrote:

On Tue, 17 Dec 2013 09:54:41 -0500, Roy Smith wrote:


In article ,
  Neil Cerutti  wrote:


On 2013-12-17, Steven D'Aprano
 wrote:

I would really like to see good quality statistics about bugs per
program written in different languages. I expect that, for all we
like to make fun of COBOL, it probably has few bugs per
unit-of-useful-work-done than the equivalent written in C.


Well, there was that little Y2K thing...


Oh come on, how were people in the 1990s supposed to predict that they
would be followed by the year 2000???

That's a good point, but that wasn't a language issue, it was a program
design issue. Back in the 70s and 80s, when saving two digits per date
field seemed to be a sensible thing to do, people simply didn't imagine
that their programs would still be used in the year 1999[1]. That's not
the same sort of bug as (say) C buffer overflows, or SQL code injection
attacks. It's not like the COBOL language defined dates as having only
two digits.




[1] What gets me is that even in the year 1999, there were still
programmers writing code that assumed two-digit years. I have it on good
authority from somebody working as an external consultant for a bank in
1999 that he spent most of 1998 and 1999 fixing *brand new code* written
by the bank's own staff. You'd think that having lived through that
experience would have shaken his belief that private enterprise does
everything better, and the bigger the corporation the better they do it,
but apparently not. Go figure.




I was in charge of the team at work that had to make all code Y2K 
compliant.  I discovered the one bug that to my knowledge slipped 
through the net.  Four years later back at the same place on contract I 
fixed the fix!!!


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Wolfgang Keller
> I was also taught C as an undergrad but having already learned Java, C
> and C++ before arriving at University I found the C course very easy
> so my own experience is not representative. Many of the other students
> at that time found the course too hard and just cheated on all the
> assignments (I remember one students offering to fix/finish anyone's
> assignment in exchange for a bottle of cider!).

The problem with the C class wasn't that it was "hard". I had passed my
Pascal class, which taught nearly exactly the same issues with
"straight A"s before (without ever having writeen any source code ever
before). And by standard cognitive testing standards, I'm not exactly
considered to be an idiot.

The only issue for me was to figure out how to do in C what I already
knew in Pascal. And I had to waste a *lot* more time and mental effort
to mess with that language than it took for me to learn *both* the
basics of programming per se *and* Pascal in the first class at my home
university.

C is just a kafkaesque mess invented by a sadistic pervert who must
have regularly consumed illegal substances for breakfast. Its only
reason to exist seems to be that apparently it's ridiculously easy to
implement a "compiler" for it. Although, as a professional developer
once told me, most C compilers are garbage.

One student in the C class (who had been doing software development for
years before he came to university) jokingly passed around samples of
"valid" C code by email. Most of them looked like uuencoded binaries
(this was in the early-to-mid 90s), but they all compiled and produced
an output. Except that *no one* (including professors) was able to
predict the output without actually running the compiled code.

In the classroom lectures parallel to the C exercises, the professor
spent most of his time explaining what *not* to do because... Heck, why
does a language provide features resp. allow their use in ways that are
known to be bottomless cans of worms.

> These types of problems are compounded by the fact that the current C
> course uses automated marking so a program that produces the correct
> output gets full marks even if it is terribly written and the student
> entirely misses the point - another thing about this course that
> definitely needs to change.

In our classes, when a program was correct, but e.g. you used just *one*
single non-semantic identifier (such as an "i" for a loop index), you
got *automatically* zero points for that exercise. Other absolutely
mandatory requirements were about minimum commenting etc. Less comment
lines than code was very likely to yield zero points for that exercise
as well.

Sincerely,

Wolfgang
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question RE urllib

2013-12-17 Thread Larry Martell
On Tue, Dec 17, 2013 at 10:26 AM, Jeff James  wrot
>
>  So I'm using the following script to check our sites to make sure they
> are all up and some of them are reporting they are "down" when, in fact,
> they are actually up.   These sites do not require a logon in order for the
> home page to come up.  Could this be due to some port being blocked
> internally ?  Only one of the sites reporting as down is "https" but all
> are internal sites.  Is there some other component I should be including in
> the script ?  There are about 30 or 40 sites that I have listed in all.  I
> just use those in the following script as examples.   Thanks
>
> import urllib
>
> sites = ["http://www.amazon.com/";, "https://internalsite.com/intranet.html";,
> etc.]
>
> for site in sites:
> try:
> urllib.urlopen(site)
> print site + " "
> except Exception, e:
> print site + " is down"
> --
> https://mail.python.org/mailman/listinfo/python-list
>
>
> I've never used urllib, although I've done a fair amount of network
> programming at lower levels.
>
> Are you sure the report of "down" isn't simply a time out due to the
> server being busier than you expect when you hit it?
>
> -Bill
>
> After adding the line suggested by Larry, I was able to determine that the
> URLs reporting as "down" were actually sites requiring authentication in
> order to provide site content, so adding that line to the handler was at
> least enlightening in that  respect.  Thanks Larry.
>
Glad to help. Here is some info on authenticating with urllib:

http://docs.python.org/2.7/howto/urllib2.html#id6

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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Larry Martell
On Tue, Dec 17, 2013 at 10:35 AM, Mark Lawrence  wrote:
> I was in charge of the team at work that had to make all code Y2K compliant.
> I discovered the one bug that to my knowledge slipped through the net.  Four
> years later back at the same place on contract I fixed the fix!!!

>From around 1997 till 2000 all I did was fix Y2K bugs. I'm pretty sure
I got them all. For one client I fixed well over 200. After the new
year came and nothing broke, the owner of the company said "You made
such a big deal about this Y2K stuff, and it turned out not to be a
problem at all."
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question RE urllib

2013-12-17 Thread Tobiah

On 12/17/2013 08:10 AM, Larry Martell wrote:

On Tue, Dec 17, 2013 at 10:26 AM, Jeff James mailto:[email protected]>> wrot


So I'm using the following script to check our sites to make sure they are 
all up and some of them are reporting they are
"down" when, in fact, they are actually up.   These sites do not require a 
logon in order for the home page to come up.  Could
this be due to some port being blocked internally ?  Only one of the sites reporting 
as down is "https" but all are internal
sites.  Is there some other component I should be including in the script ? 
 There are about 30 or 40 sites that I have listed
in all.  I just use those in the following script as examples.   Thanks

import urllib

sites = ["http://www.amazon.com/";, 
"https://internalsite.com/intranet.html";, etc.]

for site in sites:
try:
urllib.urlopen(site)
print site + " "
except Exception, e:
print site + " is down"
--
https://mail.python.org/mailman/listinfo/python-list


I've never used urllib, although I've done a fair amount of network 
programming at lower levels.

Are you sure the report of "down" isn't simply a time out due to the server 
being busier than you expect when you hit it?

-Bill

After adding the line suggested by Larry, I was able to determine that the URLs 
reporting as "down" were actually sites
requiring authentication in order to provide site content, so adding that 
line to the handler was at least enlightening in that
respect.  Thanks Larry.

Glad to help. Here is some info on authenticating with urllib:

http://docs.python.org/2.7/howto/urllib2.html#id6





It must be a network problem, cuz your code works fine:

:w !python
http://www.amazon.com/
http://google.com
http://tobiah.org
http://notavalidurl.com
http://superreallyforsurenotavalidurlnokidding.com is down

Tobiah
--
https://mail.python.org/mailman/listinfo/python-list


Python and MIDI

2013-12-17 Thread Tobiah

Is there a module out there that would let
me send a predetermined list of midi messages
to a MIDI device in such a way that the timing
would be precise enough for music?

Thanks,

Tobiah
--
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread rusi
On Tuesday, December 17, 2013 9:51:07 PM UTC+5:30, [email protected] wrote:
> On Tue, Dec 17, 2013 at 10:35 AM, Mark Lawrence wrote:
> > I was in charge of the team at work that had to make all code Y2K compliant.
> > I discovered the one bug that to my knowledge slipped through the net.  Four
> > years later back at the same place on contract I fixed the fix!!!

> > From around 1997 till 2000 all I did was fix Y2K bugs. I'm pretty
> > sure I got them all. For one client I fixed well over 200. After
> > the new > year came and nothing broke, the owner of the company
> > said "You made > such a big deal about this Y2K stuff, and it
> > turned out not to be a > problem at all."

Hahaha -- Very funny and serious.  Ive been actually experienced being
kicked out of job for writing decent working code and not making a big
deal of it.

Comes back the start of the thread -- What do we teach students?
Should we teach how to write the best possible code and as effortlessly
as possible?  Or should we also teach how to make a fuss, how to pretend
to (over)work while actually (under)delivering?

In a Utopia this would not be a question at all.
But we dont live in Utopia...

[And there are languages WAY better than C... C++ for example]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Grant Edwards
On 2013-12-17, Wolfgang Keller  wrote:

>> I was also taught C as an undergrad but having already learned Java, C
>> and C++ before arriving at University I found the C course very easy
>> so my own experience is not representative. Many of the other students
>> at that time found the course too hard and just cheated on all the
>> assignments (I remember one students offering to fix/finish anyone's
>> assignment in exchange for a bottle of cider!).
>
> The problem with the C class wasn't that it was "hard". I had passed my
> Pascal class, which taught nearly exactly the same issues with
> "straight A"s before (without ever having writeen any source code ever
> before). And by standard cognitive testing standards, I'm not exactly
> considered to be an idiot.

I agree that C is a awful pedagogical language.  When I was in
university, the first language for Computer Science or Computer
Engineering students was Pascal.  After that, there were classes that
surveyed Prolog, SNOBOL, LISP, Modula, APL, FORTRAN, COBOL, etc.  If
you were an "other" engineering/science major, you learned FORTRAN
first (and last).  I think there may also have been some business
types who were taught BASIC.

C wasn't taught at all.  When I graduated and started doing real-time
embedded firmware, the choices were Generally C or Pascal.  The first
projects I did were in Pascal, but I learned C because the development
host was a PDP-11 running Unix and I needed to write some small (non
embedded) utilities.  Today, all my embedded work is in C.  Python
fell out of style for some reason, but (with a few extensions) it was
a fine language for embedded work as well.

I've always thought C was a great language for low-level, bare-metal,
embedded stuff -- but teaching it to first or second year computer
science students is just insane.  C has a certain minimalist
orthogonality that I have always found pleasing.  [People who smile
wistfully when they think about the PDP-11 instruction word layouts
probably know what I mean.]

But, exposure to C should wait until you have a firm grasp of basic
algorithms and data structures and are proficient in assembly language
for a couple different architectures.  Ideally, you should also have
written at least one functioning compiler before learning C as well.

-- 
Grant Edwards   grant.b.edwardsYow! Maybe we could paint
  at   GOLDIE HAWN a rich PRUSSIAN
  gmail.comBLUE --
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Oscar Benjamin
On 17 December 2013 15:51, Wolfgang Keller  wrote:
>>
>> I was also taught C as an undergrad but having already learned Java, C
>> and C++ before arriving at University I found the C course very easy
>> so my own experience is not representative. Many of the other students
>> at that time found the course too hard and just cheated on all the
>> assignments (I remember one students offering to fix/finish anyone's
>> assignment in exchange for a bottle of cider!).
>
> The problem with the C class wasn't that it was "hard". I had passed my
> Pascal class, which taught nearly exactly the same issues with
> "straight A"s before (without ever having writeen any source code ever
> before). And by standard cognitive testing standards, I'm not exactly
> considered to be an idiot.

Please don't misunderstand me: I'm certainly not saying that you're an
idiot. Also I'm sure many of the students on my course would have
fared better on a course that was using e.g. Python instead of C.

Well actually come to think of it some of the other students were
pretty stupid. The lecturer had explained that they were using a
plagiarism detector so if you copy-paste code from someone else they
could catch you out for cheating. A few people took that literally and
thought that it could detect copy-pasting (in plain text files!). The
rumour went round that it would be okay if you printed out the code
and then typed it back in. For some reason they didn't bother running
the plagiarism detector until about 6 weeks into the course by which
time ~20% of submissions were exact duplicates of at least one other
(according to the lecturer who announced that all such students would
get zero marks for those assignments).


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New to Python, Help to get script working?

2013-12-17 Thread rusi
On Tuesday, December 17, 2013 4:35:31 PM UTC+5:30, Mark wrote:
> I am sorry, using google groups i cant tell what you see...
> Anyways, I guess i will just make lots of lines instead of long sentences?

> How about this, the first person that can get this to work for me...
> I will paypal them 20 dollars for helping me.
> I just want to get this thing up and going.
> Ive posted where i am having trouble and got 2 replies talking about 
> spacing...
> and not fixing any issues or giving advice.

> Either that or somebody who thinks they might be able to help, can you plz 
> reply?

I believe you were given a suggestion by Steven on posting a traceback
Did you follow that?  (Genuine question!!)
Because if you did and it got lost in the characteristic 'GG-crap' you would
not know that it had been 'crapified' by GG and others would not know that
there was anything to read in the mess.

So... assuming youve understood the following:

1. Read and follow https://wiki.python.org/moin/GoogleGroupsPython
2. Read and follow Steven's advice on how to ask help especially regarding 
errors
3. Try to minimize external links to code especially small snippets

maybe best to just start a new thread???
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Larry Martell
On Tue, Dec 17, 2013 at 11:59 AM, Grant Edwards  wrote:
> On 2013-12-17, Wolfgang Keller  wrote:
>
>>> I was also taught C as an undergrad but having already learned Java, C
>>> and C++ before arriving at University I found the C course very easy
>>> so my own experience is not representative. Many of the other students
>>> at that time found the course too hard and just cheated on all the
>>> assignments (I remember one students offering to fix/finish anyone's
>>> assignment in exchange for a bottle of cider!).

I did that, but my fee was a case of beer.

>>
>> The problem with the C class wasn't that it was "hard". I had passed my
>> Pascal class, which taught nearly exactly the same issues with
>> "straight A"s before (without ever having writeen any source code ever
>> before). And by standard cognitive testing standards, I'm not exactly
>> considered to be an idiot.
>
> I agree that C is a awful pedagogical language.  When I was in
> university, the first language for Computer Science or Computer
> Engineering students was Pascal.  After that, there were classes that
> surveyed Prolog, SNOBOL, LISP, Modula, APL, FORTRAN, COBOL, etc.  If
> you were an "other" engineering/science major, you learned FORTRAN
> first (and last).  I think there may also have been some business
> types who were taught BASIC.
>
> C wasn't taught at all.

It wasn't for me either when I went to college in the late 1970's.
Pascal first, then FORTRAN, then IBM 360 assembler. That was all the
formal language training I had. (I had taught myself BASIC in high
school.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Mark Lawrence

On 17/12/2013 17:18, Larry Martell wrote:

On Tue, Dec 17, 2013 at 11:59 AM, Grant Edwards  wrote:

On 2013-12-17, Wolfgang Keller  wrote:


I was also taught C as an undergrad but having already learned Java, C
and C++ before arriving at University I found the C course very easy
so my own experience is not representative. Many of the other students
at that time found the course too hard and just cheated on all the
assignments (I remember one students offering to fix/finish anyone's
assignment in exchange for a bottle of cider!).


I did that, but my fee was a case of beer.



Pay bottle get monkey?

--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


ANN: Version 0.1.2 of sarge (a subprocess wrapper library) has been released.

2013-12-17 Thread Vinay Sajip
Version 0.1.2 of Sarge, a cross-platform library which wraps the subprocess
module in the standard library, has been released.

What changed?
-

- Fixed issue #12: Prevented a hang which occurred when a redirection failed.

- Fixed issue #11: Added "+" to the characters allowed in parameters.

- Fixed issue #10: Removed a spurious debugger breakpoint.

- Fixed issue #9: Relative pathnames in redirections are now relative to the
  current working directory for the redirected process.

- Added the ability to pass objects with "fileno()" methods as values
  to the "input" argument of "run()", and a "Feeder" class which
  facilitates passing data to child processes dynamically over time (rather
  than just an initial string, byte-string or file).

- Added functionality under Windows to use PATH, PATHEXT and the
  registry to find appropriate commands. This can e.g. convert a
  command 'foo bar', if 'foo.py' is a Python script in the
  c:\Tools directory which is on the path,  to the equivalent
  'c:\Python26\Python.exe c:\Tools\foo.py bar'. This is done internally
  when a command is parsed, before it is passed to subprocess.

- Fixed issue #7: Corrected handling of whitespace and redirections.

- Fixed issue #8: Added a missing import.

- Added Travis integration.

- Added encoding parameter to the "Capture" initializer.

- Fixed issue #6: addressed bugs in Capture logic so that iterating over
  captures is closer to subprocess behaviour.

- Tests added to cover added functionality and reported issues.

- Numerous documentation updates.

What does Sarge do?
---

Sarge tries to make interfacing with external programs from your
Python applications easier than just using subprocess alone.

Sarge offers the following features:

* A simple way to run command lines which allows a rich subset of Bash-
style shell command syntax, but parsed and run by sarge so that you
can run on Windows without cygwin (subject to having those commands
available):

>>> from sarge import capture_stdout
>>> p = capture_stdout('echo foo | cat; echo bar')
>>> for line in p.stdout: print(repr(line))
...
'foo\n'
'bar\n'

* The ability to format shell commands with placeholders, such that
  variables are quoted to prevent shell injection attacks.

* The ability to capture output streams without requiring you to
  program your own threads. You just use a Capture object and then you
  can read from it as and when you want.

* The ability to look for patterns in captured output and to interact
  accordingly with the child process.

Advantages over subprocess
---

Sarge offers the following benefits compared to using subprocess:

* The API is very simple.

* It's easier to use command pipelines - using subprocess out of the
box often leads to deadlocks because pipe buffers get filled up.

* It would be nice to use Bash-style pipe syntax on Windows, but
Windows shells don't support some of the syntax which is useful, like
&&, ||, |& and so on. Sarge gives you that functionality on Windows,
without cygwin.

* Sometimes, subprocess.Popen.communicate() is not flexible enough for
one's needs - for example, when one needs to process output a line at
a time without buffering the entire output in memory.

* It's desirable to avoid shell injection problems by having the
ability to quote command arguments safely.

* subprocess allows you to let stderr be the same as stdout, but not
the other way around - and sometimes, you need to do that.

Python version and platform compatibility
-

Sarge is intended to be used on any Python version >= 2.6 and is
tested on Python versions 2.6, 2.7, 3.1, 3.2 and 3.3 on Linux,
Windows, and Mac OS X (not all versions are tested on all platforms,
but sarge is expected to work correctly on all these versions on all
these platforms).

Finding out more


You can read the documentation at

http://sarge.readthedocs.org/

There's a lot more information, with examples, than I can put into
this post.

You can install Sarge using "pip install sarge" to try it out. The
project is hosted on BitBucket at

https://bitbucket.org/vinay.sajip/sarge/

And you can leave feedback on the issue tracker there.

I hope you find Sarge useful!

Regards,

Vinay Sajip

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


Re: New to Python, Help to get script working?

2013-12-17 Thread Rick Johnson
On Monday, December 16, 2013 1:09:38 AM UTC-6, Mark wrote:
> On Sunday, December 15, 2013 9:33:17 PM UTC-5, Chris Angelico wrote:
> > I went and looked at the post linked to, and it has
> > buggy indentation. (Quite possibly indicates that the
> > author has two-space tabs, and didn't notice a bug
> > slipping in. I dunno.) Along the way, though, I learned
> > that the script in question is entirely for generating
> > fake twitch.tv viewers so as to get your stream
> > highlighted fraudulently, so I'm rather less inclined to
> > help. Got a legitimate use for this, or are you just
> > trying to cheat your way to fame?
> > 
> Thanks for the reply, the answer is yes and no, i already
> have about 2400 followers and half mil views, i just
> wanted to see if i could get it to work.

That's like a serial spammer saying """I already have 2400
spam bots and half a million victims but i just want to get
my latest bot working for "academic" purposes only. *wink*"""

Listen Mark, it's obvious you don't have any coding or
debugging skills and all you want to do is employ this app
for your own fraudulent purposes, so with that in mind:

NO SOUP FOR YOU!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New to Python, Help to get script working?

2013-12-17 Thread Joel Goldstick
On Tue, Dec 17, 2013 at 12:33 PM, Rick Johnson  wrote:

> On Monday, December 16, 2013 1:09:38 AM UTC-6, Mark wrote:
> > On Sunday, December 15, 2013 9:33:17 PM UTC-5, Chris Angelico wrote:
> > > I went and looked at the post linked to, and it has
> > > buggy indentation. (Quite possibly indicates that the
> > > author has two-space tabs, and didn't notice a bug
> > > slipping in. I dunno.) Along the way, though, I learned
> > > that the script in question is entirely for generating
> > > fake twitch.tv viewers so as to get your stream
> > > highlighted fraudulently, so I'm rather less inclined to
> > > help. Got a legitimate use for this, or are you just
> > > trying to cheat your way to fame?
> > >
> > Thanks for the reply, the answer is yes and no, i already
> > have about 2400 followers and half mil views, i just
> > wanted to see if i could get it to work.
>
> That's like a serial spammer saying """I already have 2400
> spam bots and half a million victims but i just want to get
> my latest bot working for "academic" purposes only. *wink*"""
>
> Listen Mark, it's obvious you don't have any coding or
> debugging skills and all you want to do is employ this app
> for your own fraudulent purposes, so with that in mind:
>
> NO SOUP FOR YOU!
> --
> https://mail.python.org/mailman/listinfo/python-list
>

I'm kinda with Rick on this thread.  A guy walks along with a name like
markshizzle, offers $20 to make his 'thing' work, and proudly admits he
doesn't want to know how the program works, he just wants it to work.  I
don't think this is the right place for you markshizzle.  This is a place
for people who are interested in improving their python skills, and asking
question after they have done there best to learn on their own first.
$20?  .. as they used to say on "are you being served':   go boil your head

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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Mark Lawrence

On 17/12/2013 16:59, Grant Edwards wrote:


I've always thought C was a great language for low-level, bare-metal,
embedded stuff -- but teaching it to first or second year computer
science students is just insane.  C has a certain minimalist
orthogonality that I have always found pleasing.  [People who smile
wistfully when they think about the PDP-11 instruction word layouts
probably know what I mean.]


I agree with you here, but wasn't there a tie-in between C and the rise 
of Unix via universities, or am I barking in the wrong forest?




But, exposure to C should wait until you have a firm grasp of basic
algorithms and data structures and are proficient in assembly language
for a couple different architectures.  Ideally, you should also have
written at least one functioning compiler before learning C as well.



I never had a problem with C as I'd written assembler for RCA 1802, 
Ferranti F110L and DEC/VAX, plus CORAL 66.  Hum, a bit of a fib there, I 
recall vainly struggling with a C for loop before I finally realised I'd 
effectively written a CORAL 66 one, page 50 here 
http://www.xgc.com/manuals/pdf/xgc-c66-rm.pdf for (ouch!!!) anyone who's 
interested.  Using a Whitesmith's pre-ANSI C compiler didn't exactly 
help me either.   IIRC printf was spelt format and all the formatting 
codes were different to what became standard C.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread rusi
On Tuesday, December 17, 2013 8:21:39 PM UTC+5:30, Neil Cerutti wrote:
> On 2013-12-17, Steven D'Aprano wrote:
> > I would really like to see good quality statistics about bugs
> > per program written in different languages. I expect that, for
> > all we like to make fun of COBOL, it probably has few bugs per
> > unit-of-useful-work-done than the equivalent written in C.

> I can't think of a reference, but I to recall that
> bugs-per-line-of-code is nearly constant; it is not language
> dependent. So, unscientifically, the more work you can get done
> in a line of code, then the fewer bugs you'll have per amount of
> work done.

Enter the (One-Liner) Dragon!

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

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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Michael Torrie
On 12/17/2013 08:00 AM, Wolfgang Keller wrote:
>> Python is sooo slow when it waits for the human.
> 
> With Windows systems, I waste something like 90% of my work time waiting
> for that system to stop "Not Responding".
> 
> And no, it's not a matter of hardware.

Something is wrong then.  Windows has its issues, and it does slow down
over time as cruft in the system accumulates. And Windows XP is getting
slower and slower due to a bug in the automatic updates service, but in
general, but your experience with Windows is not normal.  I managed
hundreds of Windows workstations in my previous life and I did not see
this occur with any regularity. So something is wrong with your setup.
Maybe its time for a re-install?  Virus or malware?  Or maybe you need
to upgrade to Windows 7?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Terry Reedy

On 12/17/2013 10:07 AM, Wolfgang Keller wrote:


On an actual operating system, the attitude of the developers (do they
actually care or just don't give a darn) is *the* critical issue for
end-user productivity. If a developer makes a statement such as
of "just get a faster computer" or "just get more RAM", then (s)he
probably doesn't give darn. C++ applications, just like Java
applications, tend to leak horrible amounts of memory these days, just
because the vendors/developers don't care.


I'll note that Python core developers do care about memory leaks. At 
least one module is tested for memory leaks in a nightly task. When 
found, leaks are patched.


--
Terry Jan Reedy

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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Chris Angelico
On Wed, Dec 18, 2013 at 5:03 AM, rusi  wrote:
> On Tuesday, December 17, 2013 8:21:39 PM UTC+5:30, Neil Cerutti wrote:
>> I can't think of a reference, but I to recall that
>> bugs-per-line-of-code is nearly constant; it is not language
>> dependent. So, unscientifically, the more work you can get done
>> in a line of code, then the fewer bugs you'll have per amount of
>> work done.
>
> Enter the (One-Liner) Dragon!
>
> http://www.youtube.com/watch?v=a9xAKttWgP4

Some languages work differently with lines, cramming more onto a
single line while still having more "code". What's nearly constant is
bugs per "amount of code", except that it's practically impossible to
measure how much code you've produced. So there are a few exceptions
to the "lines of code" metric, a few languages that jump around a bit
on the scale.

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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Michael Torrie
On 12/17/2013 08:00 AM, Wolfgang Keller wrote:
>> Please check JYTHON and those ready-for-novice GUI tools in java.
> 
> All Java GUI frameworks I know of are ridiculous garbage.
> 
> Not only that Java per se is obscenely fat (and unresponsive), but the
> GUI frameworks leak like bottomless barrels and the look and feel is so
> hideous that I would say from personal experience with numerous Java
> applications that there is little that's worse for user productivity
> than a Java application running on Windows. Well, a "web application"
> might top it.

Pray tell is there anything that is not ridiculous garbage or is your
computer so hopelessly broken that everything fails on it?  You've
already dissed on Windows, Firefox, the web, Java.  Surely Python must
suck also because it's slow and interpreted.
-- 
https://mail.python.org/mailman/listinfo/python-list


PDFMiner install question

2013-12-17 Thread Jason Mellone
Hello,

I have python up and running using the exact setup as recommended by 
http://learnpythonthehardway.org/

I am now trying to use pdfminer.

I have python here:
C:\USERS\Python27

using "import os", i am able to cwd to C:\users\python where i have 
C:\users\python\pdfminer-master\.

when i navigate to the child directory and run "setup.py install" i get the 
following issue:

>>> setup.py install
  File "", line 1
setup.py install
   ^

i have no idea why, any input?

thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PDFMiner install question

2013-12-17 Thread Mark Lawrence

On 17/12/2013 20:06, Jason Mellone wrote:

Hello,

I have python up and running using the exact setup as recommended by 
http://learnpythonthehardway.org/

I am now trying to use pdfminer.

I have python here:
C:\USERS\Python27

using "import os", i am able to cwd to C:\users\python where i have 
C:\users\python\pdfminer-master\.

when i navigate to the child directory and run "setup.py install" i get the 
following issue:


setup.py install

   File "", line 1
 setup.py install
^

i have no idea why, any input?

thanks!



The "import os" tells me that you're running setup.py from a Python 
prompt, you should be running it from a Windows command prompt.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Gene Heskett
On Tuesday 17 December 2013 12:23:28 Cousin Stanley did opine:

> >> Rick Johnson  wrote:
> >>  Dovetails are nothing more than sadistic nostalgia --
> >>  they give old men a "chubby" and young men a nightmare.
> > 
> > There is nothing more satisfying than cutting a set of dovetails by
> > hand and having them glide together like silk, the first time you
> > test-fit them, with no daylight visible anywhere.
> 
>This dove-tailer understands Rapid Application Development 
> 
>   http://woodwork.ars-informatica.ca/tool.php?art=dovetail_video
>   Frank Klausz's three-minute dovetails using a bow saw

Frank is a Master, and too many people never really learn to use a bow saw.  
However I'd expect that joint would take more glue to fill, I've had a 
single drop of TB-III extrude from every edge of one of my jig made joints.

But, I really think we are just a tad off topic.

Cheers, Gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page 

UNIX is hot.  It's more than hot.  It's steaming.  It's quicksilver
lightning with a laserbeam kicker.
-- Michael Jay Tucker
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
 law-abiding citizens.
-- 
https://mail.python.org/mailman/listinfo/python-list


Multiprocessing pool with custom process class

2013-12-17 Thread Sergey Fedorov
Hi All,

I have a web-service that needs to handle a bunch of work requests. Each
job involves IO call (DB, external web-services to fetch some data), so
part of the time is spent on the blocking IO call. On the other side, after
getting the data the job involves computational part (using numpy/pandas on
time series dataframes).
Service runs on multicore machine, so I want to use parallelism as much as
possible (especially considering python's GIL) and due to decent number of
IO, I want to use multiple threads inside each process so none of CPUs will
stale due to IO delays.

It'd be the best scenario to use pool of processes and thread pool (because
each worker will need to keep some state, like db connections). I already
have my own thread pool implementation, that uses some load-balancing and
fair-scheduling techniques that are specific to my problem domain.

I'm curious if there is any multiprocessing module that I missed and which
I can reuse. As it turned out, the on in the multiprocessing module doesn't
support custom Process class (if there were, I would be able to derive it
and add the functionality I need) (
http://stackoverflow.com/questions/740844/python-multiprocessing-pool-of-custom-processes).
Is there any alternative module that I can reuse?

If not, what's the best way to notify caller that the task finished its
execution (aka multiprocessing.Pool's apply() function behavior)? What
primitives are better to use for that purpose (in case I'll have to go with
my own implementation of multiprocessing pool)? Any reference to good
blog/educational resource will be highly appreciated!

If you believe that my solution is not optimal and have better/easier
solution (hope I specified my problem good enough), please share your
thoughts

Thanks in advance!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Grant Edwards
On 2013-12-17, Mark Lawrence  wrote:
> On 17/12/2013 16:59, Grant Edwards wrote:
>>
>> I've always thought C was a great language for low-level, bare-metal,
>> embedded stuff -- but teaching it to first or second year computer
>> science students is just insane.  C has a certain minimalist
>> orthogonality that I have always found pleasing.  [People who smile
>> wistfully when they think about the PDP-11 instruction word layouts
>> probably know what I mean.]
>
> I agree with you here, but wasn't there a tie-in between C and the rise 
> of Unix via universities, or am I barking in the wrong forest?

Yes, I think the popularity of Unix on university campuses is what
caused the migration from Pascal to C for freshman programming
classes.  IIRC, there were decent Pascal compilers for Unix back then,
so I still think it was a big mistake.  Later on when studying low
level OS stuff would have been a fine time to introduce C if required
for logistical reasons.

-- 
Grant Edwards   grant.b.edwardsYow! Vote for ME -- I'm
  at   well-tapered, half-cocked,
  gmail.comill-conceived and
   TAX-DEFERRED!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Saving binaries in a specific way

2013-12-17 Thread Djoser
Thank you.
With numpy it works perfectly. I thought it would lost the information about 
int32 and int16 with this approach.

Now I will try to make the script with struct too, but I'll need a bit more 
time to really understand. For me it's a new paradigm. But that's nice. :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PDFMiner install question

2013-12-17 Thread MRAB

On 17/12/2013 20:06, Jason Mellone wrote:

Hello,

I have python up and running using the exact setup as recommended by 
http://learnpythonthehardway.org/

I am now trying to use pdfminer.

I have python here:
C:\USERS\Python27

using "import os", i am able to cwd to C:\users\python where i have 
C:\users\python\pdfminer-master\.

when i navigate to the child directory and run "setup.py install" i get the 
following issue:


setup.py install

   File "", line 1
 setup.py install
^

i have no idea why, any input?

thanks!


Do you really have the ">>>" prompt? If yes, then you're asking Python
to run a console (OS) command.

You should be running "setup.py install" in a console ("Command
Prompt") window, something like:

cd C:\users\python\pdfminer-master
C:\USERS\Python27\python.exe \setup.py install

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


Re: PDFMiner install question

2013-12-17 Thread Jason Mellone
On Tuesday, December 17, 2013 3:32:56 PM UTC-5, MRAB wrote:
> On 17/12/2013 20:06, Jason Mellone wrote:
> 
> > Hello,
> 
> >
> 
> > I have python up and running using the exact setup as recommended by 
> > http://learnpythonthehardway.org/
> 
> >
> 
> > I am now trying to use pdfminer.
> 
> >
> 
> > I have python here:
> 
> > C:\USERS\Python27
> 
> >
> 
> > using "import os", i am able to cwd to C:\users\python where i have 
> > C:\users\python\pdfminer-master\.
> 
> >
> 
> > when i navigate to the child directory and run "setup.py install" i get the 
> > following issue:
> 
> >
> 
>  setup.py install
> 
> >File "", line 1
> 
> >  setup.py install
> 
> > ^
> 
> >
> 
> > i have no idea why, any input?
> 
> >
> 
> > thanks!
> 
> >
> 
> Do you really have the ">>>" prompt? If yes, then you're asking Python
> 
> to run a console (OS) command.
> 
> 
> 
> You should be running "setup.py install" in a console ("Command
> 
> Prompt") window, something like:
> 
> 
> 
> cd C:\users\python\pdfminer-master
> 
> C:\USERS\Python27\python.exe \setup.py install

ok makes sense.

i am running now from command line and get the following:

P:\>C:\USERS\Python27\python.exe C:\users\Python27\pdfminer-master\setup.py inst
all
running install
running build
running build_py
error: package directory 'pdfminer' does not exist

P:\>



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


Re: PDFMiner install question

2013-12-17 Thread Jason Mellone
On Tuesday, December 17, 2013 3:53:24 PM UTC-5, Jason Mellone wrote:
> On Tuesday, December 17, 2013 3:32:56 PM UTC-5, MRAB wrote:
> 
> > On 17/12/2013 20:06, Jason Mellone wrote:
> 
> > 
> 
> > > Hello,
> 
> > 
> 
> > >
> 
> > 
> 
> > > I have python up and running using the exact setup as recommended by 
> > > http://learnpythonthehardway.org/
> 
> > 
> 
> > >
> 
> > 
> 
> > > I am now trying to use pdfminer.
> 
> > 
> 
> > >
> 
> > 
> 
> > > I have python here:
> 
> > 
> 
> > > C:\USERS\Python27
> 
> > 
> 
> > >
> 
> > 
> 
> > > using "import os", i am able to cwd to C:\users\python where i have 
> > > C:\users\python\pdfminer-master\.
> 
> > 
> 
> > >
> 
> > 
> 
> > > when i navigate to the child directory and run "setup.py install" i get 
> > > the following issue:
> 
> > 
> 
> > >
> 
> > 
> 
> >  setup.py install
> 
> > 
> 
> > >File "", line 1
> 
> > 
> 
> > >  setup.py install
> 
> > 
> 
> > > ^
> 
> > 
> 
> > >
> 
> > 
> 
> > > i have no idea why, any input?
> 
> > 
> 
> > >
> 
> > 
> 
> > > thanks!
> 
> > 
> 
> > >
> 
> > 
> 
> > Do you really have the ">>>" prompt? If yes, then you're asking Python
> 
> > 
> 
> > to run a console (OS) command.
> 
> > 
> 
> > 
> 
> > 
> 
> > You should be running "setup.py install" in a console ("Command
> 
> > 
> 
> > Prompt") window, something like:
> 
> > 
> 
> > 
> 
> > 
> 
> > cd C:\users\python\pdfminer-master
> 
> > 
> 
> > C:\USERS\Python27\python.exe \setup.py install
> 
> 
> 
> ok makes sense.
> 
> 
> 
> i am running now from command line and get the following:
> 
> 
> 
> P:\>C:\USERS\Python27\python.exe C:\users\Python27\pdfminer-master\setup.py 
> inst
> 
> all
> 
> running install
> 
> running build
> 
> running build_py
> 
> error: package directory 'pdfminer' does not exist
> 
> 
> 
> P:\>

also this is my dir:
P:\>dir C:\users\python27\pdfminer-master
 Volume in drive C has no label.
 Volume Serial Number is B825-02BA

 Directory of C:\users\python27\pdfminer-master

17/12/2013  02:55 PM  .
17/12/2013  02:55 PM  ..
17/12/2013  02:48 PM  cmaprsrc
17/12/2013  02:48 PM  docs
26/11/2013  04:35 AM 1,723 Makefile
26/11/2013  04:35 AM   111 MANIFEST.in
17/12/2013  03:49 PM  pdfminer
26/11/2013  04:35 AM 5,311 README.md
17/12/2013  02:48 PM  samples
26/11/2013  04:35 AM 1,384 setup.py
17/12/2013  02:48 PM  tools
   4 File(s)  8,529 bytes
   7 Dir(s)  26,006,282,240 bytes free

P:\>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Packaging a private project

2013-12-17 Thread Thomas Heller

Am 16.12.2013 12:18, schrieb Nicholas Cole:

Dear List,

What is the best way to distribute a private, pure python, Python 3
project that needs several modules (some available on pypi but some
private and used by several separate projects) in order to run?

I'd like to include everything that my project needs to run in a
single package.  The best way to do this seems to be to be to create
symlinks to the source code of the "3rd party" modules I need and
create a setup.py file that includes them in its "packages" list.  Is
this what other people do?

But even more ideally, I'd like to package my script and its
dependencies in a single zip file that can be executed by python
directly.  I see several declarations that this is possible online,
but I can't find a simple recipe for converting a script and its
dependencies into this kind of distribution. Could someone give me a
pointer to a description of "the right way to do it".

I'm making life harder for myself by using python 3 (PyInstaller still
only supports Python 2) and by the fact that I can't release some of
the necessary code publicly.  Releasing modules and scripts on pypi
has become very easy -- I'd forgotten how hard packaging private code
is!


Well, pyzzer comes to mind (you find it on pypi).  It creates an
executable zip-archive containing all the stuff that you need (at least
the pure python modules).

The problem remains: how to find all the modules and packages that need
to be included?

Python's modulefinder can do this for you.  If you want to live on the
cutting edge you could try the new one that I've written for Python3.
It currently lives in

http://code.google.com/p/ctypes-stuff/source/browse/trunk/mf/py2exe/mf3.py

It has several advantages against the standard library's modulefinder;
for example it finds and is able to extract the bytecode even from
zipped eggs.
For examples how it can be used, you could peek into the runtime.py
module in the same directory, method build_library of class Runtime.

I guess for an experienced developer it takes around one day to take
these pieces and build a script that scans a python script, finds all
the needed modules and packages, and uses pyzzer to build an executable
archive from it.

Thomas
--
https://mail.python.org/mailman/listinfo/python-list


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Mark Lawrence

On 17/12/2013 19:00, [email protected] wrote:

Le mardi 17 décembre 2013 19:06:35 UTC+1, Michael Torrie a écrit :

On 12/17/2013 08:00 AM, Wolfgang Keller wrote:


Python is sooo slow when it waits for the human.







With Windows systems, I waste something like 90% of my work time waiting



for that system to stop "Not Responding".







And no, it's not a matter of hardware.




Something is wrong then.  Windows has its issues, and it does slow down

over time as cruft in the system accumulates. And Windows XP is getting

slower and slower due to a bug in the automatic updates service, but in

general, but your experience with Windows is not normal.  I managed

hundreds of Windows workstations in my previous life and I did not see

this occur with any regularity. So something is wrong with your setup.

Maybe its time for a re-install?  Virus or malware?  Or maybe you need

to upgrade to Windows 7?




I tend to agree with you. However, I should say
I'm observing a strange phenomenon.

Among others, I wrote two interactive interpreters
with PySide 1.1.2 for Python 3.3 and Python 3.2.

If I'm runing such a task with Py3.2 (more than a minute)


timeit.timeit("a = '\u2345'*10; 'x' in a")


it runs smoothly.

but if I run the same task with Py3.3

my window seems to be idled, and a message like,
Ne répond pas (something like "Do no respond")
appeares in the title bar of the window (my application
title + that msg). The cursor get transformed into the
win7 "waiting cursor".

The app seems to freeze, but in fact, it is not and
the resulting values are correct.

How do I know this? Very simple, the resulting
values are in exact concordance with the values
I obtain with my interactive intepreters, but
built with tkinter!

jmf



Have I understood this correctly?  Your users are using a GUI that 
you've designed and implemented, they type in 10 identical 
characters and then search linearly for a single character that they 
know can't possibly be found, and then they are complaining that their 
systems are too slow, yes?


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Joel Goldstick
On Tue, Dec 17, 2013 at 1:20 PM, Chris Angelico  wrote:

> On Wed, Dec 18, 2013 at 5:03 AM, rusi  wrote:
> > On Tuesday, December 17, 2013 8:21:39 PM UTC+5:30, Neil Cerutti wrote:
> >> I can't think of a reference, but I to recall that
> >> bugs-per-line-of-code is nearly constant; it is not language
> >> dependent. So, unscientifically, the more work you can get done
> >> in a line of code, then the fewer bugs you'll have per amount of
> >> work done.
> >
>
If its true that bugs per line of code is more or less a constant, I think
the key is that some languages are more expressive than others.  So, in
assembler, you are moving data around registers, and doing basic math,
etc.  It takes a lot of code to get something done.  So maybe more bugs.
Moving up the ladder to C, which is in a way high level assembly language,
you get more done in few lines.  Python or other languages maybe do more
per line than C  (eg the for loop in python does a lot with very little
code because of python having iterable stuff built in)  So, if you have a
language that is expressive and fits your programming needs, you will have
less to debug -- not because you don't make as many errors, but the good
code just does more for you


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


Re: PDFMiner install question

2013-12-17 Thread Mark Lawrence

On 17/12/2013 20:59, Jason Mellone wrote:

On Tuesday, December 17, 2013 3:53:24 PM UTC-5, Jason Mellone wrote:

On Tuesday, December 17, 2013 3:32:56 PM UTC-5, MRAB wrote:


On 17/12/2013 20:06, Jason Mellone wrote:







Hello,















I have python up and running using the exact setup as recommended by 
http://learnpythonthehardway.org/















I am now trying to use pdfminer.















I have python here:







C:\USERS\Python27















using "import os", i am able to cwd to C:\users\python where i have 
C:\users\python\pdfminer-master\.















when i navigate to the child directory and run "setup.py install" i get the 
following issue:















setup.py install







File "", line 1







  setup.py install







 ^















i have no idea why, any input?















thanks!















Do you really have the ">>>" prompt? If yes, then you're asking Python







to run a console (OS) command.















You should be running "setup.py install" in a console ("Command







Prompt") window, something like:















cd C:\users\python\pdfminer-master







C:\USERS\Python27\python.exe \setup.py install




ok makes sense.



i am running now from command line and get the following:



P:\>C:\USERS\Python27\python.exe C:\users\Python27\pdfminer-master\setup.py inst

all

running install

running build

running build_py

error: package directory 'pdfminer' does not exist



P:\>


also this is my dir:
P:\>dir C:\users\python27\pdfminer-master
  Volume in drive C has no label.
  Volume Serial Number is B825-02BA

  Directory of C:\users\python27\pdfminer-master

17/12/2013  02:55 PM  .
17/12/2013  02:55 PM  ..
17/12/2013  02:48 PM  cmaprsrc
17/12/2013  02:48 PM  docs
26/11/2013  04:35 AM 1,723 Makefile
26/11/2013  04:35 AM   111 MANIFEST.in
17/12/2013  03:49 PM  pdfminer
26/11/2013  04:35 AM 5,311 README.md
17/12/2013  02:48 PM  samples
26/11/2013  04:35 AM 1,384 setup.py
17/12/2013  02:48 PM  tools
4 File(s)  8,529 bytes
7 Dir(s)  26,006,282,240 bytes free

P:\>



Hi, glad to see you're making some progress :)  You're likely to get 
more offers of assistance if you read and action this 
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the 
double line spacing above, thanks.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread wxjmfauth
Le mardi 17 décembre 2013 19:06:35 UTC+1, Michael Torrie a écrit :
> On 12/17/2013 08:00 AM, Wolfgang Keller wrote:
> 
> >> Python is sooo slow when it waits for the human.
> 
> > 
> 
> > With Windows systems, I waste something like 90% of my work time waiting
> 
> > for that system to stop "Not Responding".
> 
> > 
> 
> > And no, it's not a matter of hardware.
> 
> 
> 
> Something is wrong then.  Windows has its issues, and it does slow down
> 
> over time as cruft in the system accumulates. And Windows XP is getting
> 
> slower and slower due to a bug in the automatic updates service, but in
> 
> general, but your experience with Windows is not normal.  I managed
> 
> hundreds of Windows workstations in my previous life and I did not see
> 
> this occur with any regularity. So something is wrong with your setup.
> 
> Maybe its time for a re-install?  Virus or malware?  Or maybe you need
> 
> to upgrade to Windows 7?



I tend to agree with you. However, I should say
I'm observing a strange phenomenon.

Among others, I wrote two interactive interpreters
with PySide 1.1.2 for Python 3.3 and Python 3.2.

If I'm runing such a task with Py3.2 (more than a minute)

>>> timeit.timeit("a = '\u2345'*10; 'x' in a")

it runs smoothly.

but if I run the same task with Py3.3

my window seems to be idled, and a message like,
Ne répond pas (something like "Do no respond")
appeares in the title bar of the window (my application
title + that msg). The cursor get transformed into the
win7 "waiting cursor".

The app seems to freeze, but in fact, it is not and
the resulting values are correct.

How do I know this? Very simple, the resulting
values are in exact concordance with the values
I obtain with my interactive intepreters, but
built with tkinter!

jmf

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


Re: Type of an object:

2013-12-17 Thread Gregory Ewing

Steven D'Aprano wrote:
Well, that is a surprise, but I don't think that is intended behaviour. I 
think that's something which only works by accident. The intention is 
that __class__ returns the instance's type, not arbitrary values.


Well, a proxy object would obviously return a suitable
class-like object. I was just demonstrating that it's
possible to override what __class__ returns.

I don't think it's an accident, because the weakref
module uses this for its proxy objects.

>>> import weakref
>>> class C(object):
...  pass
...
>>> c = C()
>>> p = weakref.proxy(c)
>>> p.__class__

>>> type(p)


If you 
try to set it to a non-class on the instance, it fails:


For proxying purposes you don't need to be able to set
it, but I don't see why you couldn't use a property
setter to override that behaviour as well if you really
wanted to.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: PDFMiner install question

2013-12-17 Thread MRAB
On 17/12/2013 20:59, Jason Mellone wrote:> On Tuesday, December 17, 2013 
3:53:24 PM UTC-5, Jason Mellone wrote:

>> On Tuesday, December 17, 2013 3:32:56 PM UTC-5, MRAB wrote:
>>> On 17/12/2013 20:06, Jason Mellone wrote:
 Hello,

 I have python up and running using the exact setup as recommended 
by http://learnpythonthehardway.org/


 I am now trying to use pdfminer.

 I have python here:
 C:\USERS\Python27

 using "import os", i am able to cwd to C:\users\python where i 
have C:\users\python\pdfminer-master\.


 when i navigate to the child directory and run "setup.py install" 
i get the following issue:


>>> setup.py install
 File "", line 1
   setup.py install
  ^

 i have no idea why, any input?

 thanks!

>>> Do you really have the ">>>" prompt? If yes, then you're asking Python
>>> to run a console (OS) command.
>>>
>>> You should be running "setup.py install" in a console ("Command
>>> Prompt") window, something like:
>>>
>>> cd C:\users\python\pdfminer-master
>>> C:\USERS\Python27\python.exe \setup.py install
>>
>> ok makes sense.
>>
>> i am running now from command line and get the following:
>>
>> P:\>C:\USERS\Python27\python.exe 
C:\users\Python27\pdfminer-master\setup.py inst

>> all
>> running install
>> running build
>> running build_py
>> error: package directory 'pdfminer' does not exist
>>
>> P:\>
>
> also this is my dir:
> P:\>dir C:\users\python27\pdfminer-master
>   Volume in drive C has no label.
>   Volume Serial Number is B825-02BA
>
>   Directory of C:\users\python27\pdfminer-master
>
> 17/12/2013  02:55 PM  .
> 17/12/2013  02:55 PM  ..
> 17/12/2013  02:48 PM  cmaprsrc
> 17/12/2013  02:48 PM  docs
> 26/11/2013  04:35 AM 1,723 Makefile
> 26/11/2013  04:35 AM   111 MANIFEST.in
> 17/12/2013  03:49 PM  pdfminer
> 26/11/2013  04:35 AM 5,311 README.md
> 17/12/2013  02:48 PM  samples
> 26/11/2013  04:35 AM 1,384 setup.py
> 17/12/2013  02:48 PM  tools
> 4 File(s)  8,529 bytes
> 7 Dir(s)  26,006,282,240 bytes free
>
> P:\>
>
The prompt shows that the current directory is P:\.

On Windows, each drive has its own current directory, so you have to
set the default drive too.

I think this should do it:

C:
cd C:\users\Python27\pdfminer-master
C:\USERS\Python27\python.exe setup.py inst
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python and MIDI

2013-12-17 Thread Dave Angel
On Tue, 17 Dec 2013 08:45:28 -0800, Tobiah  
wrote:

Is there a module out there that would let
me send a predetermined list of midi messages
to a MIDI device in such a way that the timing
would be precise enough for music?


Probably.  I haven't tried it but I'd look first at pygame.  Maybe 
first at:


http://www.pygame.org/wiki/MidiScheduler

--
DaveA

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


Re: Type of an object:

2013-12-17 Thread Steven D'Aprano
On Wed, 18 Dec 2013 11:15:03 +1300, Gregory Ewing wrote:

> Steven D'Aprano wrote:
>> Well, that is a surprise, but I don't think that is intended behaviour.
>> I think that's something which only works by accident. The intention is
>> that __class__ returns the instance's type, not arbitrary values.
> 
> Well, a proxy object would obviously return a suitable class-like
> object. I was just demonstrating that it's possible to override what
> __class__ returns.

You can certainly do it with a __getattribute__ method:

py> class K(object):
... def __getattribute__(self, name):
... if name == '__class__': return 42
... return super().__getattribute__(name)
...
py> k = K()
py> k.__class__
42

but I think that counts as "shoot yourself in the foot" category.


> I don't think it's an accident, because the weakref module uses this for
> its proxy objects.

Just a minute, we seem to be talking about completely different things 
here. You demonstrated setting __class__ to a non-class object inside a 
class statement, emphasis on the *non-class* part. Here's a simpler 
version showing the same thing:

py> class Q(object):
... __class__ = 42
...
py> q = Q()
py> q.__class__
42
py> type(q)



Here's an equivalent way:

py> Q = type("Q", (object,), {'__class__': 23})
py> Q().__class__
23

It's the *non-class* part I reckon is an accident, or a bug. Telling me 
that weakproxy sets __class__ to a *class* doesn't argue for or against 
me.

Ignoring virtual __getattribute__ attributes, I cannot see any other way 
to set the __class__ of an object to be a non-class. (I suppose you can 
do anything you like with a metaclass, but that falls firmly into 
"consenting adults" territory.) Unless you "break" access to the 
__class__ descriptor first, as in the Q class above, there doesn't seem 
to be any way to set it to a non-class or an incompatible class. You 
can't set it on the class:

py> class C(object):
... pass
...
py> C.__class__ = 23
Traceback (most recent call last):
  File "", line 1, in 
TypeError: __class__ must be set to a class, not 'int' object
py> C.__dict__['__class__'] = 23
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'mappingproxy' object does not support item assignment


nor can you set it on the instance:

py> c = C()
py> c.__class__ = 23
Traceback (most recent call last):
  File "", line 1, in 
TypeError: __class__ must be set to a class, not 'int' object


You can set it on the instance dict directly, but it doesn't do you any 
good because the descriptor overrides it:

py> c.__dict__['__class__'] = 23
py> c.__class__



Somebody has gone to a *lot* of trouble to ensure that __class__ always 
returns an actual class, and I'm not sure the Q example above is a 
deliberate hole in that.


Your weakref example is not a counter-example:

>  >>> import weakref
>  >>> class C(object):
> ...  pass
> ...
>  >>> c = C()
>  >>> p = weakref.proxy(c)
>  >>> p.__class__
> 
>  >>> type(p)
> 


since both weakproxy and C are classes. This is a good example though of 
when type(obj) and obj.__class__ can legitimately differ.

This leads to another question: we've now seen two examples where 
(presumably) the internal type field and __class__ differ. In the 
weakproxy case, type(obj) returns the internal type field. In the 
"regular" case, where you set obj.__class__ to a class, type(obj) returns 
the new (external) type. How the hell does it decide which one to return?



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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Roy Smith
In article <[email protected]>,
 Wolfgang Keller  wrote:

> C is just a kafkaesque mess invented by a sadistic pervert who must
> have regularly consumed illegal substances for breakfast. 

Don't be absurd.  C is a perfectly good language for the kinds of things 
it's meant for.  It lets you get down close to the hardware while still 
using rational flow control and program structure, and being reasonably 
portable.

There's very few mysteries in C.  You never have to wonder what the 
lifetime of an object is, or be mystified by which of the 7 signatures 
of Foo.foo() are going to get called, or just what operation "x + y" is 
actually going to perform.

If you maim yourself with a razor-sharp chisel, do you blame the chisel 
for being a bad tool?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Roy Smith
In article ,
 Grant Edwards  wrote:

> Ideally, you should also have written at least one functioning 
> compiler before learning C as well.

Why?  I've never written a compiler.  I've written plenty of C.  I don't 
see how my lack of compiler writing experience has hindered my ability 
to write C.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Steven D'Aprano
On Tue, 17 Dec 2013 19:32:20 -0500, Roy Smith wrote:

> There's very few mysteries in C.

Apart from "What the hell does this piece of code actually do?". It's no 
coincidence that C, and Perl which borrows a lot of syntax from C, are 
the two champion languages for writing obfuscated code.

And "What does 'implementation-specific undefined behaviour' actually 
mean in practice?", another common question when dealing with C.

And most importantly, "how many asterisks do I need, and where do I put 
them?" (only half joking).


> You never have to wonder what the
> lifetime of an object is, 

Since C isn't object oriented, the lifetime of objects in C is, um, any 
number you like. "The lifetime of objects in  is ONE MILLION YEARS!!!" is as good as any other vacuously true 
statement.


> or be mystified by which of the 7 signatures
> of Foo.foo() are going to get called, 

Is that even possible in C? If Foo is a struct, and Foo.foo a member, I 
don't think C has first-class functions and so Foo.foo can't be callable. 
But if I'm wrong, and it is callable, then surely with no arguments there 
can only be one signature that Foo.foo() might call, even if C supported 
generic functions, which I don't believe it does.

(You can simulate something rather like generic functions using pointers, 
but that's it.)


> or just what operation "x + y" is
> actually going to perform.


With no operator overloading, that one at least is correct.



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


Re: Type of an object:

2013-12-17 Thread Ethan Furman

On 12/17/2013 03:51 PM, Steven D'Aprano wrote:


This leads to another question: we've now seen two examples where
(presumably) the internal type field and __class__ differ. In the
weakproxy case, type(obj) returns the internal type field. In the
"regular" case, where you set obj.__class__ to a class, type(obj) returns
the new (external) type. How the hell does it decide which one to return?


However it does it, it does it in C.  ;)

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Chris Angelico
On Wed, Dec 18, 2013 at 12:33 PM, Steven D'Aprano  wrote:
> On Tue, 17 Dec 2013 19:32:20 -0500, Roy Smith wrote:
>
>> There's very few mysteries in C.
>
> Apart from "What the hell does this piece of code actually do?". It's no
> coincidence that C, and Perl which borrows a lot of syntax from C, are
> the two champion languages for writing obfuscated code.

I thought APL would beat both of them, though you're right that the
International Obfuscoted Python Code Contest would be a quite
different beast. But maybe it'd be just as viable... a competent
programmer can write unreadable code in any language.

> And "What does 'implementation-specific undefined behaviour' actually
> mean in practice?", another common question when dealing with C.

You mean like mutating locals()? The only difference is that there are
a lot more implementations of C than there are of Python (especially
popular and well-used implementations). There are plenty of things you
shouldn't do in Python, but instead of calling them
"implementation-specific undefined behaviour", we call them
"consenting adults" and "shooting yourself in the foot".

> And most importantly, "how many asterisks do I need, and where do I put
> them?" (only half joking).

The one differentiation that I don't like is between the . and ->
operators. The distinction feels like syntactic salt. There's no
context when both are valid, save in C++ where you can create a
"pointer-like object" that implements the -> operator (and has the .
operator for its own members).

>> You never have to wonder what the
>> lifetime of an object is,
>
> Since C isn't object oriented, the lifetime of objects in C is, um, any
> number you like. "The lifetime of objects in  objects> is ONE MILLION YEARS!!!" is as good as any other vacuously true
> statement.

Lifetime still matters. The difference between automatic and static
variables is lifetime - you come back into this function and the same
value is there waiting for you. Call it "values" or "things" instead
of "objects" if it makes you feel better, but the consideration is
identical. (And in C++, it becomes critical, with object destructors
being used to release resources. So you need to know.)

>> or be mystified by which of the 7 signatures
>> of Foo.foo() are going to get called,
>
> Is that even possible in C? If Foo is a struct, and Foo.foo a member, I
> don't think C has first-class functions and so Foo.foo can't be callable.
> But if I'm wrong, and it is callable, then surely with no arguments there
> can only be one signature that Foo.foo() might call, even if C supported
> generic functions, which I don't believe it does.

Well, okay. In C you can't have Foo.foo(). But if that were Foo_foo(),
then the point would be better made, because C will have just one
function of that name (barring preprocessor shenanigans, of course).
In C++, the types of its arguments may affect which function is called
(polymorphism), and the dot notation works, too; but C++ does this
without having first-class functions, so that part of your response is
immaterial. In C++, Foo.foo() will always call a function foo defined
in the class of which Foo is an instance. Very simple, and static type
analysis will tell you exactly which function that is. Things do get a
bit messier with pointers, because a function might be virtual or not
virtual; C++ gives us the simple option (non-virtual functions) that
most high level languages don't (C++'s virtual functions behave the
same way as Python member functions do).

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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Devin Jeanpierre
On Tue, Dec 17, 2013 at 4:32 PM, Roy Smith  wrote:
> There's very few mysteries in C.  You never have to wonder what the
> lifetime of an object is

Yes you do. Lifetimes are hard, because you need to malloc a lot, and
there is no defined lifetime for pointers -- they could last for just
the lifetime of a stack frame, or until the end of the program, or
anywhere in-between, and it's impossible to know for sure, and if you
get it wrong your program crashes. So there's all these conventions
you have to come up with like "borrowing" and "owning", but they
aren't compiler-enforced, so you still have to figure it out, and you
will get it wrong. Successors like C++ mitigate these issues with
destructors (allowing heap-allocated stuff to be tied to the lifetime
of a stack), and smart pointers and so on.

> , or be mystified by which of the 7 signatures
> of Foo.foo() are going to get called

C still has overloaded functions, just fewer of them. It'll still
mystify you when you encounter it, though.
http://www.robertgamble.net/2012/01/c11-generic-selections.html

> , or just what operation "x + y" is
> actually going to perform.

I don't know. Will it do float addition? int addition? size_t
addition? How does coercion work?

+ can do many different things, it's not just a straight translation
to an obvious machine instruction.

> If you maim yourself with a razor-sharp chisel, do you blame the chisel
> for being a bad tool?

If I didn't need it to be that sharp, then yes.

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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Chris Angelico
On Wed, Dec 18, 2013 at 1:33 PM, Devin Jeanpierre
 wrote:
> On Tue, Dec 17, 2013 at 4:32 PM, Roy Smith  wrote:
>> There's very few mysteries in C.  You never have to wonder what the
>> lifetime of an object is
>
> Yes you do. Lifetimes are hard, because you need to malloc a lot, and
> there is no defined lifetime for pointers -- they could last for just
> the lifetime of a stack frame, or until the end of the program, or
> anywhere in-between, and it's impossible to know for sure, and if you
> get it wrong your program crashes. So there's all these conventions
> you have to come up with like "borrowing" and "owning", but they
> aren't compiler-enforced, so you still have to figure it out, and you
> will get it wrong. Successors like C++ mitigate these issues with
> destructors (allowing heap-allocated stuff to be tied to the lifetime
> of a stack), and smart pointers and so on.

Wrong. A pointer is a scalar value, usually some kind of integer, and
its lifetime is the same as any other scalar. Heap memory's lifetime
is also very simple: it lasts until freed. (Though technically that's
not even a part of the language - malloc/free are just functions. Not
that it matters. Anyway, C++ has the new and delete operators, which
are part of the language.) There are conventions to prevent memory
leaks, but those are mere conventions. It's simple in the same way
that a toy electric motor is simple: you apply current to it, and it
spins. There's so little that it can do that it HAS to be simple.

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


Re: Is it more CPU-efficient to read/write config file or read/write sqlite database?

2013-12-17 Thread Cameron Simpson
On 15Dec2013 18:07, Tim Chase  wrote:
> >   + only lets one process access the db at a time, taking you back
> > to a similar situation as with config files
> 
> Is this a Python limitation?  According to the docs[1], it's not a
> sqlite limitation (except, as noted, on non-locking filesystems like
> NFS)

I stand corrected. I may have been mislead by apps that keep the
write lock excessively.

> >   + only lets you access the db from the same thread in which it
> > was opened, outstandingly annoying; I've had to gratuitously
> > refactor code because of this
> 
> I do believe that limitation does hold though depending on the
> build-options with which sqlite was compiled [2], though it might be
> somewhat different from within Python where the GIL could
> possibly prevent actual OS-level-thread issues.

The GIL might allow this in principle. In practice, I've had to
jump through hoops in Python to force all db ops to happen in a
particular thread.

> >   + traditionally, sqlite is extreme fsync() happy; forces a disc
> > level flush on each commit - extremely slow on busy databases,
> > not to mention hard of drives
> 
> I'd say this is the right thing for a DB to do.  If it comes back
> from a commit() call, it better be on that disk, barring a failure
> of the physical hardware.  If it comes back from a commit() and data
> gets lost because of a power-failure, something is wrong.

Depends on your view. People seem to treat dbs as some special form
of data storage. I don't; to me they're no different to storing
data in any other file. Do you do an fsync() every time you close
a file you've written? Of course not, it is a gratuitous performance
loss.  IMO, I've handed the data to the filesystem layer; its
integrity is now the OS's problem.

Now, if you _want_ to fsync on every commit, be my guest. It could
even be the default behaviour. But FFS let me turn it off easily.

The situation is made worse by fsync() implementations that are
equivalent to whole-filesystem sync(). (I'm looking at you, Linux
ext3!)

> > > * well, except on NFS shares and other places where file-locking
> > > is unreliable
> > 
> > Backing off to config files, making a lock directory is NFS safe.
> > So is opening a lock file for write with zero permissions (low level
> > open with mode=0).
> 
> Interesting.  I haven't used NFS in a long time for anything other
> than quick experiments, so it's nice to file this away.  Do you have
> a link to some official docs corroborating what you state?

Only that I'm fairly sure mkdir and open are NFS primitives. They
take place atomicly at the remote end. You can't mkdir something
twice (EEXIST) and an open with mode=0 creates an unwritable file.
A subsequent open-for-write-with=mode=0 will fail, lacking write
permission.
-- 
Cameron Simpson 

Knox's box is a 286. Fox in Socks does hacks and tricks
Knox's box is hard to fix.   To fix poor Knox's box for kicks.
- David Mar ,
  as quoted by John Mackin 
-- 
https://mail.python.org/mailman/listinfo/python-list


seeking a framework to automate router configurations

2013-12-17 Thread Frank Cui
Hi Pythoners,
I'm looking for a tool or framework in which I can do a slight modification to 
achieve the following task:
"Asynchronously reset a large number of cisco routers back to their original 
configurations and push prepared initial configurations to them"
I did find some similar existing work such as exscript and trigger, however I 
was stuck in the following two problems :
1. telneting to a non-default port number (other than 23)2. handling of 
customized banner messages.
can you give some hints on this ?  Thanks in advance for your input.
Frank

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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Devin Jeanpierre
On Tue, Dec 17, 2013 at 7:01 PM, Chris Angelico  wrote:
> On Wed, Dec 18, 2013 at 1:33 PM, Devin Jeanpierre
>  wrote:
>> Yes you do. Lifetimes are hard, because you need to malloc a lot, and
>> there is no defined lifetime for pointers -- they could last for just
>> the lifetime of a stack frame, or until the end of the program, or
>> anywhere in-between, and it's impossible to know for sure, and if you
>> get it wrong your program crashes. So there's all these conventions
>> you have to come up with like "borrowing" and "owning", but they
>> aren't compiler-enforced, so you still have to figure it out, and you
>> will get it wrong. Successors like C++ mitigate these issues with
>> destructors (allowing heap-allocated stuff to be tied to the lifetime
>> of a stack), and smart pointers and so on.
>
> Wrong. A pointer is a scalar value, usually some kind of integer, and
> its lifetime is the same as any other scalar.

The duration of a pointer's validity is far more interesting, and that
is why it is the primary meaning of the term "pointer lifetime". Also,
it's obviously what I meant.

>  Heap memory's lifetime
> is also very simple: it lasts until freed.

Sometimes simple things are hard to use correctly. I only said it was
hard, not complicated.

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


Logger module in python

2013-12-17 Thread smilesonisamal
Hi,
  I am a newbie in python. I am looking for a existing module which I can 
import in my program to log the objects to a file?

I know there is a module Data::Dumper in perl which dumps the objects to file. 
But not sure about python.

Can anybody help me in this regard?

Regards
Pradeep
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Logger module in python

2013-12-17 Thread Mark Lawrence

On 18/12/2013 03:22, [email protected] wrote:

Hi,
   I am a newbie in python. I am looking for a existing module which I can 
import in my program to log the objects to a file?

I know there is a module Data::Dumper in perl which dumps the objects to file. 
But not sure about python.

Can anybody help me in this regard?

Regards
Pradeep



http://docs.python.org/3/library/logging.html

--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: seeking a framework to automate router configurations

2013-12-17 Thread Chris Angelico
On Wed, Dec 18, 2013 at 1:40 PM, Frank Cui  wrote:
> "Asynchronously reset a large number of cisco routers back to their original
> configurations and push prepared initial configurations to them"

>From the sound of your partial solutions, this is done over a TCP/IP
socket? I don't know how you'd go about authenticating yourself with
the router (unless the factory reset is done some other way, and the
telnet part is just to push the config, in which case you'd be using
the default credentials), but presumably you've worked that part out
already.

Python has a socket module which is probably what you want here. You
can connect on any port, read what comes back, and send whatever you
need. If the job's simple enough, you might even be able to just
connect, send a fixed blob of text, and then listen for errors in the
response... or even not, and just let the user try it afterwards.

http://docs.python.org/3/library/socket.html

Does that look like what you need?

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


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-17 Thread Chris Angelico
On Wed, Dec 18, 2013 at 2:12 PM, Devin Jeanpierre
 wrote:
>> Wrong. A pointer is a scalar value, usually some kind of integer, and
>> its lifetime is the same as any other scalar.
>
> The duration of a pointer's validity is far more interesting, and that
> is why it is the primary meaning of the term "pointer lifetime". Also,
> it's obviously what I meant.
>>  Heap memory's lifetime
>> is also very simple: it lasts until freed.
>
> Sometimes simple things are hard to use correctly. I only said it was
> hard, not complicated.

Sure, which is why I went on to discuss the block of memory pointed
to. But the rules are a lot simpler than in Python, where something
exists until... uhh... the system feels like disposing of it. At which
point __del__ will probably be called, but we can't be sure of that.
All we know about an object's lifetime in Python is that it will
continue to live so long as we're using it. And then multiprocessing
and fork make it messier, but that's true in any language.

The original point was that C has no mysteries. I posit that this is
true because C's rules are so simple. It might well be harder to work
in this system (taking it to an extreme, Brainf* is about the simplest
Turing-complete language possible, and it's virtually impossible to
write good code in it), but it has no mysteries.

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


  1   2   >