Re: [Tutor] regex grouping/capturing

2013-06-14 Thread Albert-Jan Roskam
- Original Message -
 From: Andreas Perstinger andiper...@gmail.com
 To: tutor@python.org
 Cc: 
 Sent: Thursday, June 13, 2013 8:09 PM
 Subject: Re: [Tutor] regex grouping/capturing
 
 On 13.06.2013 17:09, Albert-Jan Roskam wrote:
 I have a string of the form required optional3 optional2 optional1
 optional3 ('optional' may be any kind of string, so it's 
 not simply
 'optional\d+'.
 I would like to use a regex so I can distinguish groups. Desired
 outcome: ('required', 'optional3', 'optional2', 
 'optional1',
 'optional3'). Below is  a fragment of the many things I have tried.
 [SNIP]
 How can I make this work?
 
 If you really want to use a regex:
 import re
 s = required optional3 optional2 optional1 optional3
 s2 = required optional1 optional2 optional3
 pattern = required|optional1|optional2|optional3
 re.findall(pattern, s)
 ['required', 'optional3', 'optional2', 
 'optional1', 'optional3']
 re.findall(pattern, s2)
 ['required', 'optional1', 'optional2', 
 'optional3']

Hi Andreas, thanks for your reply. I am trying to create a pygments regex 
lexer. It parses code and classfies it (in my case) commands, subcommands and 
keywords. AFAIK, re.findall can't be used with pygments, but maybe I am 
mistaken. The quantifier of groups (a plus sign in my case) just works 
different from what I expect. It seems that only optional (with a ?) groups 
can be used, not other quantifiers. Here's a simplfied example of the 'set' 
command that I would like to parse.
 
 s = 'set workspace = 6148 header on.'
 r = (set)\s+(header|workspace)+\s*=?\s*.*\.$
 re.search(r, s, re.I).groups()
[('set', 'workspace')]  # desired output: [('set', 'workspace', 'header')]
 r = (set)\s+(?:(header|workspace)\s*=?\s*.*)+\.$
 re.search(r, s, re.I).groups()
('set', 'workspace')  # grrr, still no luck 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regex grouping/capturing

2013-06-14 Thread Andreas Perstinger

On 14.06.2013 10:48, Albert-Jan Roskam wrote:

I am trying to create a pygments  regex lexer.


Well, writing a lexer is a little bit more complex than your original 
example suggested.


 Here's a simplfied example of the 'set' command that I would like to 
 parse.

s = 'set workspace = 6148 header on.'


As I understand it the order of the parts following set is arbitrary, 
i. e.

set workspace = 6148 header on.
is equivalent to
set header on workspace = 6148.
correct?

I'm not sure if a single regex can capture this.
But looking at the pygments docs I think you need something along the 
lines of (adapt the token names to your need):


class ExampleLexer(RegexLexer):
tokens = {
'root': [
(r'\s+', Text),
(r'set', Keyword),
(r'workspace|header', Name),
(r'\S+', Text),
]
}

Does this help?

Bye, Andreas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-14 Thread Matt D
i am trying to figure a way to to use a list to log/print my data:


#  tmplist = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is what we
want
tmplist = []
tmplist.append((str(strftime(%Y-%m-%d %H:%M:%S, localtime(
tmplist.append(field_values[nac])
tmplist.append(field_values[tgid])
tmplist.append(field_values[source])
tmplist.append(field_values[dest])
tmplist.append(field_values[algid])

When i run the code program dies like this:

tmplist.append(field_values[nac])
  ^
SyntaxError: invalid syntax

I cant figure why it stops on the third line above? Anyone have an idea?
Thanks!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-14 Thread Matt D
im sorry i dont get it.  there is too many brackets in this lin:

tmplist.append(field_values[nac])

Thats where the error is but i dont see too many brackets?

On 06/14/2013 08:56 AM, Flynn, Stephen (L  P - IT) wrote:
 Not enough closing brackets on the previous line... or actually too many
 opening brackets - you don't need all those that you have there already.
 
 
 #  tmplist = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is what
 we
 want
 tmplist = []
 tmplist.append((str(strftime(%Y-%m-%d %H:%M:%S,
 localtime(
 tmplist.append(field_values[nac])
  tmplist.append(field_values[tgid])
 tmplist.append(field_values[source])
 tmplist.append(field_values[dest])
 tmplist.append(field_values[algid])

 When i run the code program dies like this:

 tmplist.append(field_values[nac])
   ^
 SyntaxError: invalid syntax

 I cant figure why it stops on the third line above? Anyone have an
 idea?
 Thanks!
 
 
 This email and any attachment to it are confidential.  Unless you are the 
 intended recipient, you may not use, copy or disclose either the message or 
 any information contained in the message. If you are not the intended 
 recipient, you should delete this email and notify the sender immediately.
 
 Any views or opinions expressed in this email are those of the sender only, 
 unless otherwise stated.  All copyright in any Capita material in this email 
 is reserved.
 
 All emails, incoming and outgoing, may be recorded by Capita and monitored 
 for legitimate business purposes. 
 
 Capita exclude all liability for any loss or damage arising or resulting from 
 the receipt, use or transmission of this email to the fullest extent 
 permitted by law.
 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-14 Thread Don Jennings

On Jun 14, 2013, at 9:27 AM, Matt D wrote:

 im sorry i dont get it.  there is too many brackets in this lin:
 
   tmplist.append(field_values[nac])
 
 Thats where the error is but i dont see too many brackets?

Please don't top post.

The error is not on this line, but on the previous one. See below.
 
 On 06/14/2013 08:56 AM, Flynn, Stephen (L  P - IT) wrote:
 Not enough closing brackets on the previous line... or actually too many
 opening brackets - you don't need all those that you have there already.
 
 
 #  tmplist = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is what
 we
 want
tmplist = []
tmplist.append((str(strftime(%Y-%m-%d %H:%M:%S,
 localtime(

Count the number of opening and closing parentheses. I count five opening ones, 
and only four closing. I believe the extraneous one is right before str.

Take care,
Don

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-14 Thread Steven D'Aprano

On 14/06/13 22:45, Matt D wrote:


 tmplist = []
 tmplist.append((str(strftime(%Y-%m-%d %H:%M:%S, localtime(
 tmplist.append(field_values[nac])

[...]


When i run the code program dies like this:

 tmplist.append(field_values[nac])
   ^
SyntaxError: invalid syntax

I cant figure why it stops on the third line above? Anyone have an idea?



When you get a syntax error, sometimes the actual problem occurs on the 
PREVIOUS line, but isn't detected until this line.

Go back to the previous line, the one containing strftime, and match up each 
pair of round brackets. How many Open brackets ( do you count? How many Close 
brackets ) do you count?


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-14 Thread Alan Gauld

On 14/06/13 14:27, Matt D wrote:

im sorry i dont get it.  there is too many brackets in this lin:

tmplist.append(field_values[nac])

Thats where the error is


No, that's where Python *detected* that an error existed.
The actual error is on the previous line. This is quite
common, especially in cases of mismatched parens or quotes.

There is a difference between where an error *occurs* and
where an error is *detected*.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-14 Thread Matt D
On 06/14/2013 10:27 AM, Alan Gauld wrote:
 On 14/06/13 14:27, Matt D wrote:
 im sorry i dont get it.  there is too many brackets in this lin:

 tmplist.append(field_values[nac])

 Thats where the error is
 
 No, that's where Python *detected* that an error existed.
 The actual error is on the previous line. This is quite
 common, especially in cases of mismatched parens or quotes.
 
 There is a difference between where an error *occurs* and
 where an error is *detected*.
 
got it. the error can be in the previous line.  its running now.
Thanks guys!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-14 Thread Matt D
Hey,
here is a snip of my code.

#logger code--
#  first new line
#self.logfile.write('\n')
#  date and time
#self.logfile.write('%s,'%(str(strftime(%Y-%m-%d %H:%M:%S, 
gmtime()
#  blah = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is 
what we want
tmplist = []
tmplist.append(str(strftime(%Y-%m-%d %H:%M:%S, localtime(
tmplist.append(field_values[nac])
tmplist.append(field_values[tgid])
tmplist.append(field_values[source])
tmplist.append(field_values[dest])
tmplist.append(field_values[algid])

#this prints the current row of data to the terminal
#print tmplist

# this prints the current row of data to the csv file
for item in tmplist:
self.logfile.write('%s,' % (str(item)))
self.logfile.write('\n')


#  loop through each of the TextCtrl objects
#for k,v in self.fields.items():
#  get the value of the current TextCtrl field
   # f = field_values.get(k, None)
#if f:
# check if k is the field you want
#  output the value with trailing comma
#self.logfile.write('%s,'%(str(f)))
# self.logfile.write('\n') # here is where you would put it
#end logger code---

i know its ugly.  but there is two ways to log here.  one makes a list
(current) and the other (commented out) loops through the TextCtrls and
writes.  is their a better way than what i have here? the TextCtrl
fields get their values from a pickle.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] What are these two string-formatting styles called?

2013-06-14 Thread Dotan Cohen
What are these two string-formatting styles called?
'%.3f' % x
'{0:.3f}'.format(x)

Where in the fine manual is their names shown? Thanks!

--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-14 Thread Alan Gauld

On 14/06/13 15:37, Matt D wrote:


There is a difference between where an error *occurs* and
where an error is *detected*.


got it. the error can be in the previous line.


Yeah, or more. I've seen errors that originated 3 or 4 lines back
from the reported location. So just remember that if you can't
spot it immediately start working backwards.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread Steven D'Aprano

On 15/06/13 01:23, Dotan Cohen wrote:

What are these two string-formatting styles called?
'%.3f' % x
'{0:.3f}'.format(x)


String formatting, and string formatting *wink*

Sometimes the first is called string interpolation. Sometimes it is called 
printf-style formatting, after the C function.



Where in the fine manual is their names shown? Thanks!


Like most things to do with strings, the place to start is the section on 
strings:

http://docs.python.org/3/library/stdtypes.html#text-sequence-type-str

which leads to:

http://docs.python.org/3/library/stdtypes.html#str.format

and

http://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting


For Python 2, start here instead:

http://docs.python.org/2/library/stdtypes.html



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sound implementation problems

2013-06-14 Thread eryksun
On Thu, Jun 13, 2013 at 11:55 PM, Jim Mooney cybervigila...@gmail.com wrote:

 My IDE startup script has been changed to also go to the proper working
 directory.
 BUT - Py 3.3 at the command prompt uses my 3.3 working directory, and Py 2.7
 ALSO uses the 3.3 working directory, which is not what I want, obviously.
 Those are two different sets of scripts that won't always play together.

Why would running python.exe change the current working directory?
Anyway, I don't know much about ActivePython, so I shouldn't even ask.

 Is there a way to set up each different interpreter, either Py 3.3 or Py
 2.2, to automatically change to a particular working directory when you call
 it - with a command line switch for instance? I can os.chdir after it
 starts, of course, but that's a drag and I'll forget to do it at some point.
 If I can do that from the call to Python I can make a batch file for each
 one, with two different names - and easy typing ones like Py27 and Py33 ;')

Is this for imports relative to the current directory? If so I
recommend using the user site-packages in your profile directory. Run
the following to print its location:

import site
print(site.getusersitepackages())

It's probably the following directory (but I know next to nothing
about ActivePython):

%appdata%\Python\Python??\site-packages
(substitute the 2-digit version number for ??)

Using this directory avoids sharing paths between interpreters via the
PYTHONPATH environment variable. Just add a .pth file containing the
absolute path to your personal library of modules/packages for
Python??.

 I see one possible candidate in python --help
 -c cmd : program passed in as string (terminates option list)

 But what does program passed in as a string(terminates option list) mean?
 How do I stringify import os  os.chdir('my directory') ? That's unclear to
 me.

I don't agree with the end goal here, but running a micro-script from
the shell can be convenient, especially when paired with
macros/aliases. Here's how to start Python in a particular directory:

C:\python -i -c import os; os.chdir('C:/Python33')
 os.getcwd()
'C:\\Python33'

-i drops into interactive mode after the command completes. In Windows
you have to use double quotes for the argument after -c. But
single-quotes are fine for string literals within the command.

The Windows command-line is a bit weird in that it stores
per-executable input history and aliases in the console itself instead
of in the shell. In some ways it's convenient because it lets you
define aliases that target a particular exe, such as python.exe or
cmd.exe. And if you quit and restart (the program, not the console
window), it remembers your history (press F7 for a pop-up scrollbox).
Anyway, the interface should be familiar to anyone who ever used
MS-DOS. It's doskey (no, it's not a DOS program):

C:\doskey calc=c:\python33\python -c from cmath import *;print($*)

C:\calc e**(1j*pi/3)
(0.5001+0.8660254037844386j)

$1 is parameter 1, and so on, and $* globs all of the parameters.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread Jim Mooney
On 14 June 2013 08:23, Dotan Cohen dotanco...@gmail.com wrote:

 What are these two string-formatting styles called?
 '%.3f' % x
 '{0:.3f}'.format(x)


The first one is a string Expression, using % as the overloaded operator
The second one is a string method, with .format() as the method for a
string object

put   python string expression   or   python string method   in that great
teaching tool, Google.

I know this since I'm reading that part of my python book right now and can
actually remember it. Although I fell asleep on the third page of
explanations of the more convoluted ways to use {}, which can get
convoluted indeed ;')

-- 
Jim
A noun is just a verb with the hiccups
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sound implementation problems

2013-06-14 Thread Jim Mooney
On 14 June 2013 08:49, eryksun eryk...@gmail.com wrote:

 C:\doskey calc=c:\python33\python -c from cmath import *;print($*)

 C:\calc e**(1j*pi/3)
 (0.5001+0.8660254037844386j)

 Cool. I totally forgot about doskey macros. Still could be useful, and it
 looks like they're still in win 7.


-- 
Jim
A noun is just a verb with the hiccups
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread eryksun
On Fri, Jun 14, 2013 at 12:01 PM, Jim Mooney cybervigila...@gmail.com wrote:
 On 14 June 2013 08:23, Dotan Cohen dotanco...@gmail.com wrote:

 What are these two string-formatting styles called?
 '%.3f' % x
 '{0:.3f}'.format(x)


 The first one is a string Expression, using % as the overloaded operator
 The second one is a string method, with .format() as the method for a string
 object

The str.format method is one part of the new system; the part that
you'll usually interact with. But under the hood there's a fundamental
shift that puts the object in control of its formatting via the
__format__ special method.

This works:

 from decimal import Decimal

 '{0:.27f}'.format(Decimal(1).exp())
'2.718281828459045235360287471'

or with built-in format():

 format(Decimal(1).exp(), '.27f')
'2.718281828459045235360287471'

while the old way prints the wrong value, given the Decimal object's precision:

 '%.27f' % Decimal(1).exp()
'2.718281828459045090795598298'

because it first has to be converted to a machine double-precision
float, which has 15 decimal digits of precision (15.95 to be a bit
more precise).
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread Jim Mooney
On 14 June 2013 09:40, eryksun eryk...@gmail.com wrote:


 or with built-in format():

  format(Decimal(1).exp(), '.27f')
 '2.718281828459045235360287471'


I didn't know .format() also had a builtin. Are there many methods that are
dual like that? On the one hand, it's more memorizing, but on the other it
might be a simpler syntax. My little finger has trouble finding the : key.
All those odd characters are hard to find - they didn't design keyboards
for programming. Maybe someday.

Now you're going to tell me there's a programmer's keyboard ;')
-- 
Jim
A noun is just a verb with the hiccups
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread Steven D'Aprano

On 15/06/13 03:32, Jim Mooney wrote:


Now you're going to tell me there's a programmer's keyboard ;')


http://en.wikipedia.org/wiki/Space-cadet_keyboard

http://upload.wikimedia.org/wikipedia/commons/4/47/Space-cadet.jpg


http://ageinghacker.net/hacks/apl-keyboard/apl-keyboard-2.jpg

http://www.rexswain.com/aplinfo.html


APL is a real programming language, and no, it was not intended as a joke. 
Here's an APL program to print letter diamonds like this:

   A
  B B
 C   C
  B B
   A


And here is the code:

mat⍪1 0↓⊖mat←(⌽mat),0 1↓mat←⊃(-⍳⍴letters)↑¨letters←(⎕A⍳'E')↑⎕A


http://aplwiki.com/Studio/LetterDiamonds




--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread Jim Mooney
On 14 June 2013 10:56, Steven D'Aprano st...@pearwood.info wrote:

 On 15/06/13 03:32, Jim Mooney wrote:

  Now you're going to tell me there's a programmer's keyboard ;')


 http://en.wikipedia.org/wiki/**Space-cadet_keyboardhttp://en.wikipedia.org/wiki/Space-cadet_keyboard

 http://upload.wikimedia.org/**wikipedia/commons/4/47/Space-**cadet.jpghttp://upload.wikimedia.org/wikipedia/commons/4/47/Space-cadet.jpg


 http://ageinghacker.net/hacks/**apl-keyboard/apl-keyboard-2.**jpghttp://ageinghacker.net/hacks/apl-keyboard/apl-keyboard-2.jpg

 http://www.rexswain.com/**aplinfo.htmlhttp://www.rexswain.com/aplinfo.html


Alas, it looks like development stopped on programmer's keyboards quite a
while ago. I guess I'll just wait for voice-command and I can code while I
eat a burger.

Seriously, Python would be the best adapted for voice command with its
indenting and English-like syntax. A one-line javascript program littered
with symbols, probably not. You couldn't even think it out to say it. At
least I couldn't without typing it down, defeating the whole purpose of
voice command.

Although the string formatting just mentioned brings you right back to
head-spinning one-liners of arbitrary complexity; maybe the best would be
voice-command for basice concepts, while using the keyboard for stuff that
would twist your tongue.

Of course, by the time voice command gets really good, computers will be
writing the programs, and programmers will be meta-programming using visual
syntax - combining colored and adaptable object blocks in 3-D. Back to
playing with blocks. Cool.

I'm probably going to hear that's already been done, too ;')

Jim
Knock, knock! Who's there? Me. We got no room - go away
   Three years later
Knock, knock! Who's there? Nobody Plenty of room for nobody - please
come in.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread student Tyler Northrip
In response to your points, voice command using visuals, this idea has been
explored before. In the book containment by Christian Cantrell they use
methods such as this. The main character places a helmet on his head, and
writes code using his mind. Voice command was also used as well.


Will these ideas work or even be necessary? Perhaps one day we will create
computers that rely solely on our minds, so we would only need to think a
command and the computer would carry it out. I remember something similar
from 3001: a space odyssey.

Other than voice command and our thoughts, there is the idea of having a
computer create the program for us. Is it even possible to create a
computer capable of this? It would have to be an AI, and would it even have
the creativity or ingenuity of a human programmer? Food for thought.


On Fri, Jun 14, 2013 at 12:34 PM, Jim Mooney cybervigila...@gmail.comwrote:

 On 14 June 2013 10:56, Steven D'Aprano st...@pearwood.info wrote:

 On 15/06/13 03:32, Jim Mooney wrote:

  Now you're going to tell me there's a programmer's keyboard ;')


 http://en.wikipedia.org/wiki/**Space-cadet_keyboardhttp://en.wikipedia.org/wiki/Space-cadet_keyboard

 http://upload.wikimedia.org/**wikipedia/commons/4/47/Space-**cadet.jpghttp://upload.wikimedia.org/wikipedia/commons/4/47/Space-cadet.jpg


 http://ageinghacker.net/hacks/**apl-keyboard/apl-keyboard-2.**jpghttp://ageinghacker.net/hacks/apl-keyboard/apl-keyboard-2.jpg

 http://www.rexswain.com/**aplinfo.htmlhttp://www.rexswain.com/aplinfo.html


 Alas, it looks like development stopped on programmer's keyboards quite a
 while ago. I guess I'll just wait for voice-command and I can code while I
 eat a burger.

 Seriously, Python would be the best adapted for voice command with its
 indenting and English-like syntax. A one-line javascript program littered
 with symbols, probably not. You couldn't even think it out to say it. At
 least I couldn't without typing it down, defeating the whole purpose of
 voice command.

 Although the string formatting just mentioned brings you right back to
 head-spinning one-liners of arbitrary complexity; maybe the best would be
 voice-command for basice concepts, while using the keyboard for stuff that
 would twist your tongue.

 Of course, by the time voice command gets really good, computers will be
 writing the programs, and programmers will be meta-programming using visual
 syntax - combining colored and adaptable object blocks in 3-D. Back to
 playing with blocks. Cool.

 I'm probably going to hear that's already been done, too ;')

 Jim
 Knock, knock! Who's there? Me. We got no room - go away
Three years later
 Knock, knock! Who's there? Nobody Plenty of room for nobody -
 please come in.

 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: What are these two string-formatting styles called?

2013-06-14 Thread student Tyler Northrip
In response to your points, voice command using visuals, this idea has been
explored before. In the book containment by Christian Cantrell they use
methods such as this. The main character places a helmet on his head, and
writes code using his mind. Voice command was also used as well.


Will these ideas work or even be necessary? Perhaps one day we will create
computers that rely solely on our minds, so we would only need to think a
command and the computer would carry it out. I remember something similar
from 3001: a space odyssey.

Other than voice command and our thoughts, there is the idea of having a
computer create the program for us. Is it even possible to create a
computer capable of this? It would have to be an AI, and would it even have
the creativity or ingenuity of a human programmer? Food for thought.
___

 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread Jim Mooney
 14 June 2013 11:59, student Tyler Northrip northri...@s.dcsdk12.orgwrote:

 In response to your points, voice command using visuals, this idea has
 been explored before. In the book containment by Christian Cantrell theyuse 
 methods such as this. The main character places a helmet on his head,
 and writes code using his mind. Voice command was also used as well.


Of course, the real consideration, for those thinking of programming as a
career path, is whether programmers will be as obsolete at gaslighters in
twenty years - or will they be doing some sort of weird meta-programming?

Although this is getting marvelously off-topic, so I'll end it there ;')

-- 
Jim
Then there is the lysdexic keyboard, which corrects letter-reversals as you
tpye them...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-14 Thread Dave Angel

On 06/14/2013 10:48 AM, Matt D wrote:

Hey,
here is a snip of my code.

#logger code--
#  first new line
#self.logfile.write('\n')
#  date and time
#self.logfile.write('%s,'%(str(strftime(%Y-%m-%d %H:%M:%S, 
gmtime()
#  blah = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is 
what we want
tmplist = []
tmplist.append(str(strftime(%Y-%m-%d %H:%M:%S, localtime(
tmplist.append(field_values[nac])
tmplist.append(field_values[tgid])
tmplist.append(field_values[source])
tmplist.append(field_values[dest])
tmplist.append(field_values[algid])



tmplist is an unnecessary complication.  Did you look at my sample loop, 
which I'll repeat here with a correction:



for k in FIELD_LIST_NAMES:
#  get the value of the current TextCtrl field
f = field_values.get(k, None)
if not f is None:
#output the value with trailing comma
self.logfile.write('%s,'%(str(f)))
else:
self.logfile.write(,)
self.logfile.write(\n)

This code preserves your original feature of not crashing when the C++ 
program fails to fill in all your expected keys. It also makes sure 
there will be unadorned commas for missing fields, making it possible 
for a spreadsheet to read the columns correctly.


If you want to populate a list first, by all means do so, but do it in a 
loop, using the FIELD_LIST_NAMES as keys.


One thing I didn't handle was the date field.  I'd do that by adding it 
to the field_values dict, or to a copy of it. That way, it's all 
consistent, even though one field comes from local and the rest from the 
pickle.








--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-14 Thread Matt D
On 06/14/2013 03:14 PM, Dave Angel wrote:
 On 06/14/2013 10:48 AM, Matt D wrote:
 Hey,
 here is a snip of my code.

 #logger code--
 #  first new line
 #self.logfile.write('\n')
 #  date and time
 #self.logfile.write('%s,'%(str(strftime(%Y-%m-%d %H:%M:%S,
 gmtime()
 #  blah = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is
 what we want
 tmplist = []
 tmplist.append(str(strftime(%Y-%m-%d %H:%M:%S, localtime(
 tmplist.append(field_values[nac])
 tmplist.append(field_values[tgid])
 tmplist.append(field_values[source])
 tmplist.append(field_values[dest])
 tmplist.append(field_values[algid])

 
 tmplist is an unnecessary complication.  Did you look at my sample loop,
 which I'll repeat here with a correction:
 
 
 for k in FIELD_LIST_NAMES:
 #  get the value of the current TextCtrl field
 f = field_values.get(k, None)
 if not f is None:
 #output the value with trailing comma
 self.logfile.write('%s,'%(str(f)))
 else:
 self.logfile.write(,)
 self.logfile.write(\n)
 
 This code preserves your original feature of not crashing when the C++
 program fails to fill in all your expected keys. It also makes sure
 there will be unadorned commas for missing fields, making it possible
 for a spreadsheet to read the columns correctly.
 
 If you want to populate a list first, by all means do so, but do it in a
 loop, using the FIELD_LIST_NAMES as keys.
 
 One thing I didn't handle was the date field.  I'd do that by adding it
 to the field_values dict, or to a copy of it. That way, it's all
 consistent, even though one field comes from local and the rest from the
 pickle.
 
 
yes acutally this templist business broke my code.  the TectCtrls in the
traffic panel would were not being populated and the logfile.csv was
empty.

So should i replace:

#logger code---
#  first new line
self.logfile.write('\n')
#  date and time
self.logfile.write('%s,'%(str(strftime(%Y-%m-%d %H:%M:%S,
localtime()
#  loop through each of the TextCtrl objects
for k,v in self.fields.items():
#  get the value of the current TextCtrl field
f = field_values.get(k, None)
if f:
#  output the value with trailing comma
self.logfile.write('%s,'%(str(f)))  
#end logger code 

With the code you posted above?

I am pretty sure that the reason i don't get the 'source' and 'dest'
fields is because of this:

#if the field 'duid' == 'hdu', then clear all the fields
if field_values['duid'] == 'hdu':
self.clear()

since the 'source' and 'dest' are in the LUD1 and not the HDU so it
doesn't update when the LDU1 comes through (if the LDU1) does actually
get serialized.  still haven't found a way to get to view the serialized
data.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-14 Thread Dave Angel

On 06/14/2013 03:59 PM, Matt D wrote:

On 06/14/2013 03:14 PM, Dave Angel wrote:

On 06/14/2013 10:48 AM, Matt D wrote:

Hey,
here is a snip of my code.

#logger code--
 #  first new line
 #self.logfile.write('\n')
 #  date and time
 #self.logfile.write('%s,'%(str(strftime(%Y-%m-%d %H:%M:%S,
gmtime()
 #  blah = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is
what we want
 tmplist = []
 tmplist.append(str(strftime(%Y-%m-%d %H:%M:%S, localtime(
 tmplist.append(field_values[nac])
 tmplist.append(field_values[tgid])
 tmplist.append(field_values[source])
 tmplist.append(field_values[dest])
 tmplist.append(field_values[algid])



tmplist is an unnecessary complication.  Did you look at my sample loop,
which I'll repeat here with a correction:


 for k in FIELD_LIST_NAMES:
 #  get the value of the current TextCtrl field
 f = field_values.get(k, None)
 if not f is None:
 #output the value with trailing comma
 self.logfile.write('%s,'%(str(f)))
 else:
 self.logfile.write(,)
 self.logfile.write(\n)

This code preserves your original feature of not crashing when the C++
program fails to fill in all your expected keys. It also makes sure
there will be unadorned commas for missing fields, making it possible
for a spreadsheet to read the columns correctly.

If you want to populate a list first, by all means do so, but do it in a
loop, using the FIELD_LIST_NAMES as keys.

One thing I didn't handle was the date field.  I'd do that by adding it
to the field_values dict, or to a copy of it. That way, it's all
consistent, even though one field comes from local and the rest from the
pickle.



yes acutally this templist business broke my code.  the TectCtrls in the
traffic panel would were not being populated and the logfile.csv was
empty.

So should i replace:

#logger code---
 #  first new line
 self.logfile.write('\n')
 #  date and time
 self.logfile.write('%s,'%(str(strftime(%Y-%m-%d %H:%M:%S,
localtime()
#  loop through each of the TextCtrl objects
 for k,v in self.fields.items():
 #  get the value of the current TextCtrl field
 f = field_values.get(k, None)
 if f:
 #  output the value with trailing comma
 self.logfile.write('%s,'%(str(f))) 
#end logger code 

With the code you posted above?


Don't replace anything till you understand it.  But if you think you do 
then my code replaces the part starting at the for loop.


I am pretty sure that the reason i don't get the 'source' and 'dest'
fields is because of this:

#if the field 'duid' == 'hdu', then clear all the fields
 if field_values['duid'] == 'hdu':
 self.clear()

since the 'source' and 'dest' are in the LUD1 and not the HDU so it
doesn't update when the LDU1 comes through (if the LDU1) does actually
get serialized.


I don't know anything about LUDI or HDU.  But perhaps you're saying that 
some fields aren't in every pickle, but the value in the csv for each 
line should be the last one pickled.  In that case, you have a big logic 
flaw in your code.  When you output your stuff to the logfile, you use 
only the values in field_values, not any values previously stored in 
self.fields.  Do you perhaps mean that whenever a value is missing from 
the pickle, you want to use the one from self.fields?


If you happened to want exactly this, you could add the two middle lines 
as below.  something like:


  f = field_values.get(k, None)
  if f is None:   #add me
  f = self.fields.get(k, None)#add me
  if not f is None:

But clearly, that's much more specific than you've ever been.  There are 
also better ways to do it if that's exactly what you want.




 still haven't found a way to get to view the serialized
data.


print field_values, right at the beginning of update().  Or you could 
pretty it up, by looping through its items().




--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sound implementation problems

2013-06-14 Thread Dave Angel

On 06/14/2013 11:43 AM, Jim Mooney wrote:

On 13 June 2013 21:53, Dave Angel da...@davea.name wrote:


On 06/13/2013 11:55 PM, Jim Mooney wrote:


Alan Gauld alan.ga...@btinternet.com




This is for my own convenience on my own machine. As a former webmaster I'm
of course used to idiot-proofing anything released into the wild so it is
usable by everyone on every machine ;')

The script to change directories for PyScripter is a PyScripter startup
file, not a bat file. I meant I needed an additional bat file that would do
the same for MS-DOS.


You're not running MS-DOS.  You're running a DOS BOX under Windows, 
which is a cmd shell.


 As usual I was marvelously unclear. But anyway, I

figured it out. Here is the batch for starting 2.7 and ensuring its in the
2.7 working directory. Since I'm running 2.7 and 3.3 I just want to make
sure I don't trip over my own feet. I know I could do all this with
virtualenv, but I'd rather a simple hack than all that mess. The two Pys
are now separated in every possible way:

MS batch file py27.bat

python2.7 -i -c import os;os.chdir('c:/python27/jimprogs');del(os)



That seems rather silly.  Why not

--py27.bat---
c:
cd \python27\jimprogs
python2.7 %$
-



I probably don't have the right syntax for %$, but there is a 
pseudo-variable you can use which means all the parameters that were on 
the batch file invocation.  This is the generalization of %1 %2 %3 %4


There's also a pair of cmd.exe internal commands, with names something 
like  SETLOCAL and  ENDLOCALthat let you save and restore the 
current state of the environment including drive letter and current 
directory.


--py27.bat---
SETLOCAL
c:
cd \python27\jimprogs
python2.7 %$
ENDLOCAL
-

Or you could use PUSHD and POPD if the only thing you're customizing is 
the directory.



--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread Dave Angel

On 06/14/2013 03:09 PM, Jim Mooney wrote:
SNIP


Of course, the real consideration, for those thinking of programming as a
career path, is whether programmers will be as obsolete at gaslighters in
twenty years - or will they be doing some sort of weird meta-programming?



You mean you don't write your own microcode in hex?  New fangled 
computers get between us and the hardware.  Give me instructions that 
directly manipulate voltages, and I'll be happy again.


I have to admit, though that back when I was doing microcode work, I 
wrote my own assemblers (four at least) to at least avoid typing the hex.


--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread Jim Mooney
On 14 June 2013 13:47, Dave Angel da...@davea.name wrote:

 On 06/14/2013 03:09 PM, Jim Mooney wrote:



 You mean you don't write your own microcode in hex?  New fangled computers
 get between us and the hardware.  Give me instructions that directly
 manipulate voltages, and I'll be happy again.


I guess there will always be room for people who write drivers. I'm not
sure the more advanced robots would want to tackle that  ;')

Jim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sound implementation problems

2013-06-14 Thread Jim Mooney
On 14 June 2013 13:35, Dave Angel da...@davea.name wrote:


 MS batch file py27.bat

 python2.7 -i -c import os;os.chdir('c:/python27/**jimprogs');del(os)


 That seems rather silly.  Why not

 --py27.bat---
 c:
 cd \python27\jimprogs
 python2.7 %$
 -


That's certainly easier, but since I was looking at   Python --help   and
saw the -c command I thought I'd try passing a program in as a string,
since I hadn't done that. I'm still learning and may try out weird stuff. I
just broke PyScripter and IDLE running some Fermat numbers, but discovered
they printed out just fine, at a dizzying speed, in the DOS box. It's a
useless program where you can barely read the results, but it was very
useful to find out the DOS box does something when the my IDE and IDLE
choke.  Midrange machine -this might actually work in a better IDE on a
high end machine:

import math
fermat = [x is {} and y is {}.format(x,y) for x in range(1000) for y in
range(1000)
if not isinstance(math.sqrt(x**2 + y**2),int)]

print(fermat)

DOS started printing almost instantly, which means DOS is much, much faster
than my IDE, since the entire list had to be figured before printing (which
took a long time in the IDEs ;')

Which means the IDE could fool me into thinking something takes forever to
run when it gallops in DOS. Useful to know.

Jim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread Alan Gauld

On 14/06/13 19:34, Jim Mooney wrote:


I'm probably going to hear that's already been done, too ;')


Not in 3D to my knowledge but visual programming for sure.
One example was ObjectVision from Borland on the PC. It lacked a loop 
construct because it was event driven but otherwise was a complete 
visual programming tool. I actually built a couple of business apps 
using it in the early 90's. There's a YouTube video showing the demos 
that came with it:


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

Another one, currently popular on the RaspberryPi micro computer is Scratch:

http://scratch.mit.edu/projects/editor/?tip_bar=getStarted

And on an industrial scale there are several tools that attempt to turn 
UML/SDL design  diagrams into executable code, with varying degrees of 
success.


There's nothing new under the sun :-)

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread Alan Gauld

On 14/06/13 20:09, Jim Mooney wrote:


Of course, the real consideration, for those thinking of programming as
a career path, is whether programmers will be as obsolete at gaslighters
in twenty years - or will they be doing some sort of weird meta-programming?


COBOL - COmmon Business Oriented Language.
Designed in the 1950s to enable 'ordinary business users' to write their 
own programs and thus render programmers obsolete


And by the standards of the languages I was using in the 1970/80s Python 
is a kind of weird meta programming! :-)


That's been the holy grail of computer science since its inception.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sound implementation problems

2013-06-14 Thread Jim Mooney
On 14 June 2013 08:49, eryksun eryk...@gmail.com wrote:

 On Thu, Jun 13, 2013 at 11:55 PM, Jim Mooney cybervigila...@gmail.com
 wrote:

 C:\python -i -c import os; os.chdir('C:/Python33')


Well, that didn't work anyway. Got me the right directory and the
interpeter, but I couldn't run a py file from command. Batch file didn't
work the way I wanted, either. But PYTHONSTARTUP finally worked nicely, for
my personal purposes, by running the same python script that puts
PyScripter into the right directory, based on why Py version is run. So all
is well ;')

-- 
Jim
fi yuo cna raed tihs, yuo hvae a sgtrane mnid.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread Mark Lawrence

On 14/06/2013 22:46, Alan Gauld wrote:



COBOL - COmmon Business Oriented Language.
Designed in the 1950s to enable 'ordinary business users' to write their
own programs and thus render programmers obsolete



So what COBOL couldn't achieve is now being done with Applescript.

--
Steve is going for the pink ball - and for those of you who are 
watching in black and white, the pink is next to the green. Snooker 
commentator 'Whispering' Ted Lowe.


Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread Dave Angel

On 06/14/2013 05:43 PM, Alan Gauld wrote:

On 14/06/13 19:34, Jim Mooney wrote:


I'm probably going to hear that's already been done, too ;')


Not in 3D to my knowledge but visual programming for sure.
One example was ObjectVision from Borland on the PC. It lacked a loop
construct because it was event driven but otherwise was a complete
visual programming tool. I actually built a couple of business apps
using it in the early 90's. There's a YouTube video showing the demos
that came with it:

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

Another one, currently popular on the RaspberryPi micro computer is
Scratch:

http://scratch.mit.edu/projects/editor/?tip_bar=getStarted

And on an industrial scale there are several tools that attempt to turn
UML/SDL design  diagrams into executable code, with varying degrees of
success.

There's nothing new under the sun :-)




How about the program in about 1988 called The Last One ?  It was 
supposed to be the last program you'd ever have to buy.



--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-14 Thread Jim Mooney
On 14 June 2013 18:09, Dave Angel da...@davea.name wrote:

 On 06/14/2013 05:43 PM, Alan Gauld wrote:


 Another one, currently popular on the RaspberryPi micro computer is
 Scratch:

 http://scratch.mit.edu/**projects/editor/?tip_bar=**getStartedhttp://scratch.mit.edu/projects/editor/?tip_bar=getStarted


Hey, that's fun - although my cat kept hitting the wall ;')

Jim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor