[Tutor] Html entities, beautiful soup and unicode

2010-01-19 Thread andy
Hi people

I'm using beautiful soup to rip the uk headlines from the uk bbc page.
This works rather well but there is the problem of html entities which
appear in the xml feed.
Is there an elegant/simple way to convert them into the "standard"
output? By this I mean £ going to  ? or do i have to use regexp?
and where does unicode fit into all of this?

Thanks for your help

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


[Tutor] Removing GB pound symbols from Beautiful soup output

2010-07-16 Thread Andy

Dear Nice people

I've been using beautiful soup to filter the BBC's rss feed. However, 
recently the bbc have changed the feed and it is causing me problems 
with the pound(money) symbol. The initial error was "UnicodeEncodeError: 
'ascii' codec can't encode character u'\xa3'" which means that the 
default encoding can't process this (unicode) character. I was having 
simular problems with HTML characters appearing but I used a simple 
regex system to remove/substitute them to something suitable.
I tried applying the same approach and make a generic regex patten 
(re.compile(u"""\u\[A-Fa-f0-9\]\{4\}""") but this fails because it 
doesn't follow the standard patten for ascii. I'm not sure that I 100% 
understand the unicode system but is there a simple way to 
remove/subsitute these non ascii strings?


Thanks for any help!

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


Re: [Tutor] delphi, pascal and Python

2009-06-11 Thread andy
Hi People 

The error in this code was that the free pascal compiler command listed
below included a framework command suitable only for mac compilations

fpc -MDelphi -Cirot -O1 -gl -XX -k-framework -kpython -WG -vewnhi -l
-Fu. -oPyMinMod.so PyMinMod.dpr

The removal of this framework command cause the compliation to work beautifully

However, the imported module generates a new error

ImportError: PyMinMod.so: undefined symbol: Py_InitModule4

This error seems to crop up regularly within other python programs and
I've not found an obvious solution ... Does anyone know what causes this
type of error? (I'm on 64bit ubuntu btw)

Thanks for any suggestions/help
Andy 

> 
> By the way, the error was generated by following the tutorial and
> compiling in lazarus
> 
> 
> > After Much Looking and pointers from the author, There is this most
> > excellent post by the same author at
> >
> > http://wiki.lazarus.freepascal.org/Developing_Python_Modules_with_Pascal
> >
> > This nearly works but I have issue with the linking of the new module. The
> > error is
> >
> > Linking PyMinMod.so
> > /usr/bin/ld: Python: No such file: No such file or directory
> >
> > I've no clue what the issue is and I don't understand what should be going
> > on. I'm running 64bit ubuntu. I know this might be a bit off topic, but if
> > someone could point me in the right direction, I would be rather grateful
> >
> > Thanks
> > Andy
> >
> >
> >
> >>
> >> "Marc Tompkins"  wrote
> >>
> >>>>  Is there a Method for wrapping delphi and/or pascal code into python
> >>>> like
> >>>>> SWIG?
> >>>> http://membres.lycos.fr/marat/delphi/python.htm
> >>>
> >>> That's a package to let you embed Python in Delphi; the OP wants to go
> >>> the
> >>> other direction.
> >>
> >> So it is, I didn't read the OP question closely enough.
> >>
> >> On Windows you could create a DLL and use ctypes to access it,
> >> but thats not the same as creating an importable module as could
> >> be done with SWIG
> >>
> >> Alan G.
> >>
> >>
> >> ___
> >> Tutor maillist  -  Tutor@python.org
> >> http://mail.python.org/mailman/listinfo/tutor
> >>
> >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python and google sites

2009-09-09 Thread andy
Hi people

After searching pypy and google, I was wondering if anyone has any
experience/knowledge of a python module which would enable the
interaction with Google sites?
I'm looking for a method of scripted addition of pictyres to a page on a
google site page and wondered if someone has been clever before me

Thanks for any help

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


[Tutor] Would an emulator be possible in Python?

2007-09-12 Thread Andy
Ok, I'm pretty sure the answer is no but I'm hoping that someone will
prove me wrong.  I have decided that I would like to try and write an
emulator, I'm going to start out with a couple of simpler systems like
the Chip 8 and maybe a well documented arcade game but I would like to
do an NES emulator eventually.  Is Python anywhere near fast enough to
do this and have it be playable?  I hope so because I really don't
like C/C++.

-- 
-Andy
"I have a great faith in fools; self-confidence my friends call it." –
Edgar Allen Poe
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to Practice Python?(Linpeiheng)

2007-10-01 Thread Andy
While not Python specific you could to the Ruby quizzes
(http://www.rubyquiz.com/).  Just look at the problems and write a
solution in Python.

On 10/1/07, Alan Gauld <[EMAIL PROTECTED]> wrote:
>
> "???" <[EMAIL PROTECTED]> wrote
>
> > I am learning Python. Do you know somewhere I can practice Python?
> > I means some sites where have exercises I can try solving.
>
> The Useless Python website has some exercises and other small
> projects.
> Some have solutions some don't.
>
> Also the Python Challenge web site offers a "Game" where you
> navigate through the lasyers by solving Python puzzles, each
> using a new feature of Python.
>
> > And there should be standard answer or other people's
> > answer that can be refered.
>
> This is harder. There are solutions around for spome of them
> but not "standard solutions" - I'm not sure what such a thing would
> look like in a programming context. There are no such things
> as standard solutions to programming problems, its not like
> doing math!
>
> Some solutions are nicer than othes but each usually has some merit.
>
> HTH,
>
> Alan G
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
-Andy
"I have a great faith in fools; self-confidence my friends call it." –
Edgar Allen Poe
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Best way of learning

2007-12-05 Thread andy
Dear Pythonistas

Over a year ago I dabbled in learning Python, working my way through a 
few tutorials, the Deitel's  "How to program in Python" and Hetland's 
"Practical Python", until I came across the OOP sections. My mind just 
froze up, and I found myself wondering if I had really understood 
anything at all. In addition to which I didn't have any "itch" that I 
needed to scratch so was trying to learn something without any purpose. 
So I stopped.

In the interim however I did have a few occasions to write programs and 
scripts for my GNU/Linux system to do the odd thing here and there, a 
few conversion programs and calculators. I found myself going back to 
the books and trying to figure it out again, and am proud to say that I 
have a few programs now that are probably not elegant nor the most 
efficient or stylish, but do the job.

This has re-awakened my interest in programming and as I am going back 
to basics again I am conscious that I want to approach the matter 
differently. I *don't* work in a programming environment, nor am I 
likely to ever get into development, although would be interested in 
learning ethical hacking (the idea just interests me - too many 
espionage movies as a kid I guess).

I am happy to read, and have done a fair amount, but am concerned about 
getting too overwhelmed and confused again. I acknowledge and realise 
the value of practising by scripting programs and enjoy the intellectual 
challenge of the debugging process, and trying to think through the 
trick of a particular way of cracking a problem.

So, after this long-winded introduction, I was hoping to pick the wisdom 
of this list to get some pointers of what to do/not to do to make the 
most effective use of the few hours I have to learn how to program using 
Python. So, any advice for someone in their mid-40s who would like to 
learn Python in a more methodical and effective manner?

Thanks in anticipation.

Andy


-- 

"If they can get you asking the wrong questions, they don't have to worry about 
the answers." - Thomas Pynchon, "Gravity's Rainbow"

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] wanted exercises in python

2006-04-18 Thread Andy
Well, these are from a Ruby group but I don't see any reason why you
couldn't do them in Python.

http://www.rubyquiz.com

Look through their quiz's, might find something fun to try.


-Andy
"Be who you are and be that well." - Saint Francis de Sales


On 4/18/06, Payal Rathod <[EMAIL PROTECTED]> wrote:
> Hi,
> As  I mentioned I have been reading Python a lot in last 2 months but
> lack of examples and coding is not getting me anywhere. Can someone give
> me some exercises or I can try them myself (pythonchallenge.com please
> excuse). I am reading Alan's tut now and covered Basis set and regex
> from advanced set, so please give me exercises based on those topics
> i.e. don't tell me to code a http client or a GUI based program in
> Python :)
>
> With warm regards,
> -Payal
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Is Python the language for me?

2007-01-14 Thread Andy
Hey everyone, I'm looking to get the opinions of some people with more
experience then myself.  Currently I only have time to learn one
language and I'm torn between C++ and Python.  Eventually I would like
to make a game, nothing too extravagant, a turn based strategy game to
be exact.  I'm not planning on having crazy graphics effects, I'm
going to focus on game play.  Anyway, I'm getting a little off course
here.  I want to learn one of the two mentioned languages with the end
goal to be able to make my game.  I know it's a long way off before
I'll be able to make it so please don't assume that I'm going to jump
right in expecting to make this in a matter of months.  Besides the
game, I have all kinds of ideas for small little programs that I would
like to make.

I would honestly rather use Python then C++ but I have a few concerns.
 How hard is it to manage a large project in Python vs. C++?  If I do
decide to use Python I would be using Pygame for the graphics end of
things.  From what I can tell, Pygame does not work with the current
release of Python, that's one of the things that causes me to worry.
If I finish this game and release it, are people going to constantly
be having to upgrade Python and Pygame for it to keep working?  And
how much really changes between releases?

Python has built in access to a windowing toolkit (Tkinter), C++ can
of course use the native windows/linux/mac API but that seems like
more of a hassle to me.  Once the C++ program has been compiled it's
much easier to distribute.  C++ has a much higher learning curve and
development time then Python does.  Python has a much nicer community
built around it then C++ from what I can see though.

So as you can see I feel that each language has it's own pro's and
con's and I might end up learning them both eventually.  Do you all
think Python will work for what I want right now?  My biggest concern
with Python is the upkeep involved in trying to distribute your
applications.  Do updates to Python usually cause issues?  Why would
something like Pygame work with Python 2.4 but not 2.5?

I'm sorry if this is a horribly dumb question but I've been looking
around and I can't find the answer to these on my own.  Thank you all
for any help you can give me.

-- 
-Andy
"I have a great faith in fools; self-confidence my friends call it." –
Edgar Allen Poe
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] delphi, pascal and Python

2009-05-20 Thread Andy Cheesman
Hi people

Is there a Method for wrapping delphi and/or pascal code into python like
SWIG?
I've googled to no avail, Can anyone help me?

Andy

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] delphi, pascal and Python

2009-06-02 Thread Andy Cheesman
After Much Looking and pointers from the author, There is this most
excellent post by the same author at

http://wiki.lazarus.freepascal.org/Developing_Python_Modules_with_Pascal

This nearly works but I have issue with the linking of the new module. The
error is

Linking PyMinMod.so
/usr/bin/ld: Python: No such file: No such file or directory

I've no clue what the issue is and I don't understand what should be going
on. I'm running 64bit ubuntu. I know this might be a bit off topic, but if
someone could point me in the right direction, I would be rather grateful

Thanks
Andy



>
> "Marc Tompkins"  wrote
>
>>>  Is there a Method for wrapping delphi and/or pascal code into python
>>> like
>>>> SWIG?
>>> http://membres.lycos.fr/marat/delphi/python.htm
>>
>> That's a package to let you embed Python in Delphi; the OP wants to go
>> the
>> other direction.
>
> So it is, I didn't read the OP question closely enough.
>
> On Windows you could create a DLL and use ctypes to access it,
> but thats not the same as creating an importable module as could
> be done with SWIG
>
> Alan G.
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] delphi, pascal and Python

2009-06-03 Thread Andy Cheesman

By the way, the error was generated by following the tutorial and
compiling in lazarus


> After Much Looking and pointers from the author, There is this most
> excellent post by the same author at
>
> http://wiki.lazarus.freepascal.org/Developing_Python_Modules_with_Pascal
>
> This nearly works but I have issue with the linking of the new module. The
> error is
>
> Linking PyMinMod.so
> /usr/bin/ld: Python: No such file: No such file or directory
>
> I've no clue what the issue is and I don't understand what should be going
> on. I'm running 64bit ubuntu. I know this might be a bit off topic, but if
> someone could point me in the right direction, I would be rather grateful
>
> Thanks
> Andy
>
>
>
>>
>> "Marc Tompkins"  wrote
>>
>>>>  Is there a Method for wrapping delphi and/or pascal code into python
>>>> like
>>>>> SWIG?
>>>> http://membres.lycos.fr/marat/delphi/python.htm
>>>
>>> That's a package to let you embed Python in Delphi; the OP wants to go
>>> the
>>> other direction.
>>
>> So it is, I didn't read the OP question closely enough.
>>
>> On Windows you could create a DLL and use ctypes to access it,
>> but thats not the same as creating an importable module as could
>> be done with SWIG
>>
>> Alan G.
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Ipython and refreshing changed modules

2007-06-11 Thread Andy Cheesman
Dear People

Silly question, I'm using Ipython and importing python modules  which
I've written. After a code modification, is there an easy, quick way to
refresh changed modules?
I've googled for the solutions but the answers does not seem clear!

Andy
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Automatic generation of an "all possible combinations" array

2007-06-14 Thread Andy Cheesman
Hi people

I am trying to generate an array of all possible combinations of 1, and
zeros (see example data) for a rather nice Kinetic mote Carlo program
which I am writing python. So far, I've been working out for
combinations for 4 or less species by hand as it is quick! but I am
looking to automate the process so I can compute combinations for large
  numbers of possible species.
I could automate the generation of the array by the use of multiple
loops but that doesn't seem rather pythonic. I was wondering if anyone
had any sensible suggestions or pointers for efficient mechanisms for
the array.

Many Thanks
Andy

Example Data
3 species
array([[1, 1, 1],
   [1, 1, 0],
   [1, 0, 1],
   [0, 1, 1],
   [1, 0, 0],
   [0, 1, 0],
   [0, 0, 1],
   [0, 0, 0]])
4 species
array([[1, 1, 1, 1],
   [0, 1, 1, 1],
   [1, 0, 1, 1],
   [1, 1, 0, 1],
   [1, 1, 1, 0],
   [1, 1, 0, 0],
   [1, 0, 1, 0],
   [1, 0, 0, 1],
   [0, 1, 1, 0],
   [0, 1, 0, 1],
   [0, 0, 1, 1],
   [1, 0, 0, 0],
   [0, 1, 0, 0],
   [0, 0, 1, 0],
   [0, 0, 0, 1],
   [0, 0, 0, 0]])

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Automatic generation of an "all possible combinations" array

2007-06-15 Thread Andy Cheesman
The code works great, Thanks for the speedy response. The only problem
which I can see is that the code scales very bad with the size of n.

So, as  I want a small subsection of the data (i.e lines where there are
only 4 1s, number in the code below) for a system where n is large(>20).
The idea is that this  would reduce the number of iterations dramatic
despite the individual loop taking longer to operate.(see example data).
I've modified the bit_list_maker to allow for this but it has started to
 produce rows which are identical.
Can anyone make any suggestion/improvements to the code

def bit_list_maker_mod(n, number):
x = n*number
solution_set = []
row_total = number
for i in range(x):
this_answer = []
row = 0
while i>0:
this_answer.append(i%2)
if i%2 == 1:
row +=1
i=i/2
if row == row_total:
break
while len(this_answer) The 2**n different lists that you are seeking have a direct association
> to the binary representation of the integers 0 through (2**n)-1.
> 
> You can use this fact and the "repeated division method" for converting
> numbers between different bases to generate these lists and form the
> desired list of lists:
> 
> def bit_list_maker(n):
> x = 2**n
> solution_set = []
> for i in range(x):
> this_answer = []
> while i>0:
> this_answer.append(i%2)
> i=i/2
> while len(this_answer) this_answer.append(0)
> this_answer.reverse()
> solution_set.append(this_answer)
> return solution_set
> *
> *
> Another fun way to do it is to build up the lists recursively.  The
> possibilities for n bits can be built from the possibilities for n-1
> bits by adding a 1 and a 0 to each possibility (ending up with twice as
> many elements):
> 
> def recursive_bit_list(n):
> if n==1:
> return [[0],[1]]
> else:
> return map(lambda x: x+[0], recursive_bit_list(n-1)) + \
>map(lambda x: x+[1], recursive_bit_list(n-1))
> 
> Hope this helps!
> 
> -Hugh
> 
>  
> On 6/14/07, *Andy Cheesman* <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>> wrote:
> 
> Hi people
> 
> I am trying to generate an array of all possible combinations of 1, and
> zeros (see example data) for a rather nice Kinetic mote Carlo program
> which I am writing python. So far, I've been working out for
> combinations for 4 or less species by hand as it is quick! but I am
> looking to automate the process so I can compute combinations for large
>   numbers of possible species.
> I could automate the generation of the array by the use of multiple
> loops but that doesn't seem rather pythonic. I was wondering if anyone
> had any sensible suggestions or pointers for efficient mechanisms for
> the array.
> 
> Many Thanks
> Andy
> 
> Example Data
> 3 species
> array([[1, 1, 1],
>[1, 1, 0],
>[1, 0, 1],
>[0, 1, 1],
>[1, 0, 0],
>[0, 1, 0],
>[0, 0, 1],
>[0, 0, 0]])
> 4 species
> array([[1, 1, 1, 1],
>[0, 1, 1, 1],
>[1, 0, 1, 1],
>[1, 1, 0, 1],
>[1, 1, 1, 0],
>[1, 1, 0, 0],
>[1, 0, 1, 0],
>[1, 0, 0, 1],
>[0, 1, 1, 0],
>[0, 1, 0, 1],
>[0, 0, 1, 1],
>[1, 0, 0, 0],
>[0, 1, 0, 0],
>[0, 0, 1, 0],
>[0, 0, 0, 1],
>[0, 0, 0, 0]])
> 
> ___
> Tutor maillist  -   Tutor@python.org <mailto:Tutor@python.org>
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Animating changes with Numpy arrays

2007-06-26 Thread Andy Cheesman
Hi people

Thanks to people's most excellent help with the Automatic generation of
an "all possible combinations" array. I've got a beta version of my
program working.
However, I was wondering if there is an "easy" way to animate changes
between arrays and to show the number of the loop which the program is
running i.e a print out which changes at a controlable rate I've looked
for ascii art stuff with python but there are no pointers.
At the moment, I'm review the changes by walking through a screen print
out of all changes making pattern changes hard to spot but as this is
just a minor debuging tool, I don't want to spend weeks coding it in!

Thanks
Andy

Examples

from-=> to
1 1 1   1 2 1
1 2 1   1 1 1
1 1 1   1 1 1
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] rotation within arrays

2007-07-04 Thread Andy Cheesman
Dear People,

I wondering if any of you lovely people can make a suggestion on a
problem which I have with a n dimensional array.
For example, I've a 3x3 array and I have been mapping an element from 1D
to the one directly above it. 3->12

0 1 2
3 4 5
6 7 8

 9 10 11
12 13 14
15 16 17

The problem which I have is that I now need to rotated alternative layer
of the arrays but I still need to have the original mapping i.e 3 -> 12.

0 1 2
3 4 5
6 7 8

11 14 17
10 13 16
 9 12 15

Does anyone have any suggestions for how to do this?

Thanks

Andy

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issue with iterating within lists, objects and functions

2007-08-03 Thread Andy Cheesman
Thanks for your help Kent

The error was that I was trying to assign to a non-assignable reference
as you highlighted. Everything works now

Thanks

Andy

Kent Johnson wrote:
> Andy Cheesman wrote:
>> for thing in ["top", "right", "bottom", "left"]:
>> eval("self." + thing).append("fish")
> 
> You don't need to use eval() here, use getattr() instead:
> getattr(self, thing).append('fish')
> 
>> eval("self." + thing +"_extra")
>> eval("self." + thing) = external_function(eval("self." + thing))
>> #This
>> falls
> 
> It would help if you said *how* it fails - the specific error message
> and traceback. I guess it is failing on the left side of the assignment,
> not the function call. The result of eval("self." + thing) is the value
> of self.thing, not an assignable reference. You should use getattr() and
> setattr() here:
> 
> new_value = external_function(getattr(self, thing))
> setattr(self, thing, new_value)
> 
> or in one line if you like:
> setattr(self, thing, external_function(getattr(self, thing)))
> 
> http://docs.python.org/lib/built-in-funcs.html
> 
> Kent
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Issue with iterating within lists, objects and functions

2007-08-03 Thread Andy Cheesman
Dear people,

Sorry for the vague title, I'm struggling to define the problem but an
example will be better/clearer.
If I've a list of strings, which relate to objects(lists) elsewhere in
my code, I can call list action fine within the loop but I was wondering
how do I apply an external function as shown below?

e.g

for thing in ["top", "right", "bottom", "left"]:
eval("self." + thing).append("fish")
eval("self." + thing +"_extra")
eval("self." + thing) = external_function(eval("self." + thing)) #This
falls

Thanks for your help

Andy
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] comparing two numpy arrays

2007-08-07 Thread Andy Cheesman
Hi people,

If I've two numpy arrays, is there a non-looping way of finding common
values. (the example below has identical shapes for the arrays but this
may not be the case in my scenario)

e.g
a = array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
b = array([ 5,  6,  7,  8,  9, 10, 11, 12, 13, 14])

answer = array([ 5,6,7,8,9])

Thanks

Andy
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] comparing two numpy arrays

2007-08-08 Thread Andy Cheesman
Thats a great solution, thanks! I've googled a bit for manipulation of
sets into other data structure(lists, arrays) and not seen much. Is the
only way of interconversion a brute force method?

i.e a = set([1, 2, 3])
b = []
for thing in a:
b.append(thing)

Andy


Bob Gailer wrote:
> Eric Brunson wrote:
>> Bob Gailer wrote:
>>> Andy Cheesman wrote:
>>>  
>>>> Hi people,
>>>>
>>>> If I've two numpy arrays, is there a non-looping way of finding common
>>>> values. (the example below has identical shapes for the arrays but this
>>>> may not be the case in my scenario)
>>>>
>>>> e.g
>>>> a = array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>>> b = array([ 5,  6,  7,  8,  9, 10, 11, 12, 13, 14])
>>>>
>>>> answer = array([ 5,6,7,8,9])
>>>> 
>>> Set union?
>>>
>>>   
>> Did you mean Set intersection?
> Yes. Sigh.
>>
> 
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Simple way to compare Two lists

2007-08-10 Thread Andy Cheesman
I think you could use sets, (I asked a similar question a few days ago
re numpy arrays).
ie
Convert both list to sets
use Set intersection
convert answer to lists

HTH

Andy

Tom Fitzhenry wrote:
> On Fri, Aug 10, 2007 at 02:54:44AM -0700, Jaggo wrote:
>> Can anyone think of any better way?
> 
> If SmallList and BigList are sorted (in order), there is a faster method:
> 
> def IsAPartOfList(SmallList,BigList):
> for i in BigList:
> for j in SmallList:
> if i==j:
> return true
> if i>j:
> break
> return false
> 
> (I'm not sure how encouraged using break statements are, so wait for a tutor 
> to
> answer)
> 
> If one list is already sorted but the other isn't, it may still be faster to
> sort the unsorted list then use the method above.
> 
> If neither SmallList or BigList are sorted, it's probably best to use your
> original method, which I cannot improve.
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Finding a row match within a numpy array

2007-08-13 Thread Andy Cheesman
Dear nice people

I'm trying to match a row (b) within a large numpy array (a). My most
successful attempt is below

hit = equal(b, a)
total_hits = add.reduce(hit, 1)
max_hit = argmax(total_hits, 0)
answer = a[max_hit]

where ...
a = array([[ 0,  1,  2,  3],
   [ 4,  5,  6,  7],
   [ 8,  9, 10, 11],
   [12, 13, 14, 15]])

b = array([8,  9, 10, 11])



I was wondering if people could suggest a possible more efficient route
as there seems to be numerous steps.

Thanks
Andy
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Saving Objects

2008-01-17 Thread Andy Cheesman
Hi people

I've written a complex program in python/numpy/scipy which creates a 
dictionary of objects(which takes a while to create). I am hoping to 
save these objects to disk and then access them using a different 
session, thus bypassing the time to create the objects.

My initial tests using pickle and a simple class system (shown below) 
have failed. The method shown below fails with a AttributeError: 
'FakeModule' object has no attribute 'Spod', so when I create a
an empty class Spod in the new session, it generates an IndexError:(list 
index out of range)

Is there a better way to do this?

Andy

class Spod:
 def __init__(self, name):
 self.name=name

fish = Spod("andy")
file = open("test.pickle","w")
pickle.dump(fish, file)

# New session
file = open("test.pickle","r")
pickle.load(file)





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Saving Objects

2008-01-17 Thread Andy Cheesman
That's great and it works too, thank you!

My only arising question is why should i
"derive from object, so that you get a new-style class."

I've looked online and found this 
(http://www.geocities.com/foetsch/python/new_style_classes.htm) but I 
not sure it tells why I would want to do this this way.

Thanks again for your help

Andy

Paul McGuire wrote:
> My initial tests using pickle and a simple class system (shown below) have
> failed. The method shown below fails with a AttributeError: 
> 'FakeModule' object has no attribute 'Spod', so when I create a an empty
> class Spod in the new session, it generates an IndexError:(list index out of
> range)
>
> Is there a better way to do this?
>   
>
> I'm assuming that "# New session" marks the beginning of a separate Python
> file.  The problem is that the Spod class definition is not included in the
> pickle file, so you must import that as well, before loading back the
> pickled fish object.  Do this;
>
> 1. Put Spod in its own module, let's call it spod.py.  (While you are at it,
> have Spod derive from object, so that you get a new-style class.)
> 2. Create test1.py to pickle a Spod.  Have test1.py import spod, and then
> have your code that creates spod.Spod("andy") and pickles it to test.pickle.
> 3. Create test2.py to unpickle a Spod.  Have test2.py *also* import spod,
> and then have the rest of your code that follows "# New session".  Modify
> the pickle.load statement to save the result to a variable, and then you can
> verify that its name is "andy", type is "Spod", etc.
>
> -- Paul
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] printing format with list

2008-01-24 Thread Andy Cheesman
Hi people

Is there a way to use a list with printf formating without having to 
explicitly expanding the list after the %

e.g

a = [1, 2, 3]

print """ Testing
%i, %i, %i """ %(a[0], a[1], a[2])


Cheers

Andy

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] replacing range with xrange

2008-01-28 Thread Andy Cheesman
Hi people,

After watching a nice Google video on Python 3K, and seeing the 
forthcoming removal of range, I've looked at substitution range with 
xrange within my code. Direct substitution works for 90% percent of the 
case (i.e.   for thing in xrange(number):  ), however i can't change the 
example below where I need a non-continuous range. Any suggestions?

Andy

x = range(10)  + range(20, 30)

for thing in x:
...

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] upgrading from 2.3 to 2.4.1 on Mandrake Linux 10.1

2005-09-12 Thread Andy Dani
Hi,

Which is the best location to install Python in Linux? Should it be under one 
directory or different (like lib, doc, bin etc.)?

I followed installation instructions in "inst.pdf" from python documents. I can 
see that Python 2.4.1 has been installed in /user/lib/local by standard 
installation procedure. When I launch my IDLE or "Python" at shell, Python 2.3 
comes up! Why? Do I need to upgrade any other config files? 

Also, I am looking for help in upgrading xwPython package, OpenGL package, and 
installation of BOA constructor. They go in which directories?

Thank You

Nirav

-- 
___

Search for businesses by name, location, or phone number.  -Lycos Yellow Pages

http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python 2.4.1 on Mndrk Linux 10.1 - path

2005-10-14 Thread Andy Dani
Python 2.3.2 came with the linux distribution which is located in /usr/lib.

Installed 2.4.1 in /usr/local/Python-2.4.1 

updated /etc/profile path so IDLE or "python" would point to the latest version 
(2.4.1). 

PATH="$PATH:/usr/local/Python-2.4.1/:."
export PATH

But it is still pointing to the old one unless I go 
/use/local/Python-2.4.1/python.

I want to be able to launch and run python 2.4.1, from the user account so I do 
not need to be "root" every time. 

One more question, 
what is the significance of "import readline" in pythonrc.py file? Any harm if 
I comment that line out? this line gives a problem when I launch the 2.4.1 from 
/usr/loca/Python-2.4.1 directory.

Thanks - 



-- 
___

Search for businesses by name, location, or phone number.  -Lycos Yellow Pages

http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 2.4.1 on Mndrk Linux 10.1 - path

2005-10-15 Thread Andy Dani
Thanks  Nick,

Any idea about the second question? When I python from 
/usr/loca/Python-2.4.1/bin, it does launch the interpreter but with an 
traceback error saying there is some conflict with "import readline" line on 
pythonrc.py file located somewhere in /etc/ directory. Is there any harm If I 
comment the it out (import readline)?

Thanks - Andy

- Original Message -
From: "Nick Lunt" <[EMAIL PROTECTED]>
To: "Andy Dani" <[EMAIL PROTECTED]>, tutor@python.org
Subject: RE: [Tutor] Python 2.4.1 on Mndrk Linux 10.1 - path
Date: Fri, 14 Oct 2005 20:12:33 +0100

> 
> Hi Andy,
> 
> 
> > Behalf Of Andy Dani
> >
> > Python 2.3.2 came with the linux distribution which is located in
> > /usr/lib.
> >
> > Installed 2.4.1 in /usr/local/Python-2.4.1
> >
> > updated /etc/profile path so IDLE or "python" would point to the
> > latest version (2.4.1).
> >
> > PATH="$PATH:/usr/local/Python-2.4.1/:."
> > export PATH
> >
> > But it is still pointing to the old one unless I go
> > /use/local/Python-2.4.1/python.
> >
> > I want to be able to launch and run python 2.4.1, from the user
> > account so I do not need to be "root" every time.
> 
> The default install of python on Mandrake probably install the python
> executable in /usr/bin/python.
> /usr/bin/ is in your PATH, so if you put PATH=$PATH:/usr/local/Python-2.4.1
> in /etc/profile it will still pick up the default python install.
> 
> Try typing 'which python' at the command line and see what it picks up.
> Chances are it will be /usr/bin/python.
> 
> You could solve this by either putting
> PATH=/path/to/my/wanted/python/dir:$PATH in /etc/profile (or
> ~/.bash_profile) or by putting an alias in ~/.bashrc, such as 'alias
> python='path/to/my/wanted/python/dir/python'.
> 
> What I must stress is that you do not overwrite your default python
> installation, leave it as it is, otherwise many of mandrakes GUI tools will
> no work.
> 
> I hope that helps, feel free to ask more questions about this as I have had
> to overcome the same issue on RHEL serveral times.
> 
> Hth,
> Nick .



Thank You

Andy
[EMAIL PROTECTED]
(647) 222 9073

=

He is able who thinks he is able
-Buddha



-- 
___

Search for businesses by name, location, or phone number.  -Lycos Yellow Pages

http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Open file error

2006-01-17 Thread andy senoaji
I am starting to pull my hair here. There were some postings in the past, similar to my problem, but the response was not clear enough. Sorry if you thingk I am reposting this.I am trying to run (on an XP box) a simple open file using this:

f = open(r'C:\Test.txt', 'r')

but it keeps give me nagging error of:
Traceback (most recent call last):
  File "", line 1, in -toplevel-
f = open('Test.txt', 'r')
IOError: [Errno 2] No such file or directory: 'C:\Test.txt'

I know for sure that the file is there, I even put copies of the files here and there, just to guess how python does the file search, but it
keeps giving me 'No such file or directory'. i also tried variation of the file location string, but gave me a variation of errors :). Any suggestions?Furthermore, how does Python assumes the search path? Will it look at /LIB first? How does it knows drive lettering, network mapping etc? Is there a configuration settings that I can tweak in my Python? FYI I am using Activestate's.

Thx,

Andy
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Open file error

2006-01-17 Thread andy senoaji
I'm back to my home machine, and ran again the open method, just to test my sanity Here are the results:>>> f=open(r'c:\Test.txt','r')Traceback (most recent call last):  File "", line 1, in ?
IOError: [Errno 2] No such file or directory: 'c:\\Test.txt'>>> f=open(r'c:\\Test.txt','r')Traceback (most recent call last):  File "", line 1, in ?IOError: [Errno 2] No such file or directory: 'c:Test.txt'
>>> f=open(r'C:/Test.txt','r')Traceback (most recent call last):  File "", line 1, in ?IOError: [Errno 2] No such file or directory: 'C:/Test.txt'>>> f=open('c:\\Test.txt','r')
Traceback (most recent call last):  File "", line 1, in ?IOError: [Errno 2] No such file or directory: 'c:\\Test.txt'Now with all the explanations of r, slash, double slash, and backslash, I can't really figure out what's going on.
Any hints is much appreciated.Thanks,AndyOn 1/17/06, Python <
[EMAIL PROTECTED]> wrote:
(replying back to the list also)On Tue, 2006-01-17 at 10:03 -0800, andy senoaji wrote:> Sorry for the inconsistent error message. I think I may pasted> incorretcly. I am now in a different machine, and have tested Paul's
> suggestion, and it worked. But would the 'r' tackles the escape> sequence? I may misunderstood the intent of the r' switcher here.>> Thanks,>> Andy> f = open(r'C:\Test.txt', 'r')
> This looks correct!r'C:\Test.txt' is a raw string.  The r'strings' ignore the special useof the backslash character except that a raw string must not end with abackslash.  This is strictly a convenience when entering a string.
Since Windows uses backslash as the path separator, it helps ease thepain when constructing file paths in Windows.  Raw strings are also veryhelpful when writing regular _expression_ strings which often need to have
backspace characters.Internally, a raw string is the same as any other Python string.  WhenPython displays a raw string, Python will show the backslashes as \\(doubled) because that is usually how you need to enter a backslash.
Python does not track (as far as I know) that the string originated as araw string.In regular strings, the backslash is used to mark characters that needspecial handling. '\t' is a tab character. '\n' is a newline (linefeed).
'\r' is a carriage-return (Enter Key).http://docs.python.org/ref/strings.htmlprovides the detailed documentation about how strings work and the
definitive list of backspace usages.
>> On 1/17/06, Python <[EMAIL PROTECTED]> wrote:> On Tue, 2006-01-17 at 09:11 -0800, andy senoaji wrote:
> > I am starting to pull my hair here. There were some postings
> in the> > past, similar to my problem, but the response was not clear> enough.> > Sorry if you thingk I am reposting this.> >> > I am trying to run (on an XP box) a simple open file using
> this:> > f = open(r'C:\Test.txt', 'r')> This looks correct!>> >> > but it keeps give me nagging error of:> > Traceback (most recent call last):
> >   File "", line 1, in -toplevel-> > f = open('Test.txt', 'r')> This is not the same is the line above!>> > IOError: [Errno 2] No such file or directory: 'C:\Test.txt'
> And this does not match *either* of the lines above.>> If you really use that first line, I would expect it to> work.  If you> get an error, from that line, the file will be identified as:
> 'C:\\Test.txt'>> >> > I know for sure that the file is there, I even put copies of> the files> > here and there, just to guess how python does the file
> search, but it> > keeps giving me 'No such file or directory'. i also tried> variation of> > the file location string, but gave me a variation of> errors :). Any
> > suggestions?> >> > Furthermore, how does Python assumes the search path? Will> it look> > at /LIB first? How does it knows drive lettering, network
> mapping etc?> > Is there a configuration settings that I can tweak in my> Python? FYI I> > am using Activestate's.> >> >
> > Thx,> >> > Andy> > ___> > Tutor maillist  -  
Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor> --
> Lloyd Kvam> Venix Corp>--
Lloyd KvamVenix Corp

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Open file error

2006-01-18 Thread andy senoaji
Thanks Danny & Alan,your print repr(os.listdir("C:/")) has embarrased myself :(. I found out the file name is Test.txt.txt in my c: drive. I guess I learn something here.Again ThanksAndy
On 1/17/06, Danny Yoo <[EMAIL PROTECTED]> wrote:
On Tue, 17 Jan 2006, andy senoaji wrote:> I'm back to my home machine, and ran again the open method, just to test> my sanity Here are the results:[cut]Hi Andy,Unfortunately, there are a few things that might be happening here.  You
mentioned earlier that:> I know for sure that the file is there, I even put copies of the files> here and there, just to guess how python does the file search, but itDo you mind trying the following?  I want to double check that the
filename doesn't have anything silly in it like spaces.###import osprint repr(os.listdir("C:/"))###Can you copy-and-paste what you see from this?  This will show us the
names of things in the toplevel directory, and should help to reveal whywe're having so much trouble opening up that darn file.  *grin*Good luck to you!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem installing MySQLdb under windows

2006-04-25 Thread Andy Koch
Kent Johnson wrote:
> Peter Jessop wrote:
>> I am running Python 2.4.3, MySQL 5.0.
>> On trying to install MySQLdb 1.2.1 I ran into the following problem.
>> "
>> D:\Python24\Lib\site-packages\MySQLdb>setup.py build
>> running build
>> running build_py
>> copying MySQLdb\release.py -> build\lib.win32- 2.4\MySQLdb
>> running build_ext
>> error: The .NET Framework SDK needs to be installed before building 
>> extensions f
>> or Python.
>>
>> "
>> Is it really necessary to install The .NET Framework SDK (354Mb) or is 
>> there a simpler way?
> 
> Download the windows binary, for example 
> http://prdownloads.sourceforge.net/mysql-python/MySQL-python.exe-1.2.0.win32-py2.4.zip?download
> 
> The latest version with a Windows build is 1.2.0.
> 
> Kent
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
Greetings Python group,

I have a question related to the MySQLdb, I have recently installed the 
1.2.0 version and it works fine.  However, I am running ver. 4.1 of 
MySQL and the problem is that the python client version does not support 
the new password protocol of MySQL 4.1+.  This only means that one must 
go into the MySQL and set the password using the OLD_PASSWORD function 
of MySQL.

The question, do any of the newer versions of MySQLdb support the new 
password protocol?  And if not, are there plans to implement this?

Disclosure: this is my first post in this group, also it may be worth 
noting that I'm learning python as a side effect of developing a Plone 
site.  So if my python knowledge comes across as a bit warped... well, 
Plone can sometimes be a strange thing ;)

Regards,

Andy Koch

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] die or exit function?

2006-06-13 Thread Andy Koch
Bkgd: I've been doing PHP for the last several years.

Q: In PHP there are functions die and exit which terminate processing of 
a script with an optional string output.  Is there something similar to 
this in Python?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] die or exit function?

2006-06-14 Thread Andy Koch
doug shawhan wrote:
> Hi Andy,
> 
> Putting a try:/except: loop in your __main__() (or whatever you call
> your base function) with sys.exit("Message") is pretty much the way I
> always do it.
> 
> try:
> gak = puke + die
> except:
> sys.exit("Oy!")
> 
> If you would like sys.exit() to provide you with a bit more
> information (like what actually happened during the failure and
> where!) I found this handy function:
> 
> 
> def formatExceptionInfo(maxTBlevel=5):
>   cla, exc, trbk = sys.exc_info()
>   excName = cla.__name__
>   try:
>   excArgs = exc.__dict__["args"]
>   except KeyError:
>   excArgs = ""
>   
>   excArgsString = ''
>   for item in excArgs:
>   excArgsString = excArgsString + ' ' + str(item)
>   
>   excTb = traceback.format_tb(trbk, maxTBlevel)
>   excTbString = ''
>   for item in excTb:
>   excTbString = excTbString + " " + str(item)
>   
>   report = "%s %s %s"%(excName, excArgsString, excTbString)
>   return(report)
> 
> This function now goes in most of what I do that requires error reporting.
> 
> Hope this helps!
> 
> On 6/13/06, Andy Koch <[EMAIL PROTECTED]> wrote:
>> Bkgd: I've been doing PHP for the last several years.
>>
>> Q: In PHP there are functions die and exit which terminate processing of
>> a script with an optional string output.  Is there something similar to
>> this in Python?
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
Hi Doug,

copied and pasted, thanks

although my reason for the die() was that I've started using Python to 
do DB maintenance. I find it very handy (ie IDLE) and the DB api's for 
all the different DB's I work with are nice and standardized (PHP could 
learn a thing there).  One thing that has happened, though, is that I've 
clicked (via Winders Explorer) on a .py to open it for edit only to it 
have run, which is not what I want when the code could start modifying 
data.  Thus far it hasn't caused any damage.  So my safety check is to 
do a raw_input from a commonly included module which does the sys.exit() 
if running the code is not desired.

A basic safety catch.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] UnicodeDecodeError in kinterbasdb

2007-04-05 Thread Andy Koch
Hello,

I've installed Python 25 on an XP machine, installed kinterbasdb (and 
eginix-mx-base).  Python works fine.

However, when I try to load the firebird module in IDLE I get ...


Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit 
(Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.
 >>> import kinterbasdb
Traceback (most recent call last):
   File "", line 1, in 
   File "C:\Python25\Lib\site-packages\kinterbasdb\__init__.py", line 
98, in 
 _instPath, 'bin'
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 
237: ordinal not in range(128)


..

 From searching the web I'm led to think this is related to the default 
encodings on the machine.  But I'm not sure what to do about this.

For what it's worth, I have another machine and this same library works 
just fine.

Thank You,

Andy Koch

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Hello, and a newbie question

2013-04-16 Thread Andy McKenzie
Hey folks.

I'm just starting to pick up Python, and I'd like to avoid some of the
mistakes I made in the past.  To elaborate on that, my primary
programming/scripting experience is PHP, with a little bit of Perl thrown
in.  Like so many people who write in PHP, I was entirely self-taught, and
would be the first to admit that a lot of what I've written is, well...
wrong.  It works, but it's sloppy and inefficient, because there were
standard constructions and solutions I just didn't know about.  I'd like to
avoid that with Python.

So:  my first two questions to the list.

1) Python 2.7 or 3.x?  I know I'm going to want to do some work with NLTK
(which appears to only have an alpha version out for Python 3), but I've
just gone through the hassle of dealing with an upgrade from PHP 4 to 5.3,
and I'd rather not start learning something that's already obsolete.  Any
words of advice?

2) Best practices.  I have the WROX Press Beginning Python book, which
targets Python 2.  Clearly that's of only limited value if I'm going to go
with Python 3, but it looks like it's at least going to be a good overview.
 But some of the stuff they do seems to be fairly personalized, rather than
trying to follow standards.  Should I just start out with the tutorial from
docs.python.org?  I would assume that that would start putting me in the
right habits from the beginning... is that accurate, or is there a better
way to go?

Thanks in advance,
  Andy McKenzie
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread Andy McKenzie
On Tue, Apr 16, 2013 at 4:18 PM, Dave Angel  wrote:

> On 04/16/2013 11:58 AM, Andy McKenzie wrote:
>
>> Hey folks.
>>
>> I'm just starting to pick up Python, and I'd like to avoid some of the
>> mistakes I made in the past.  To elaborate on that, my primary
>> programming/scripting experience is PHP, with a little bit of Perl thrown
>> in.  Like so many people who write in PHP, I was entirely self-taught, and
>> would be the first to admit that a lot of what I've written is, well...
>> wrong.  It works, but it's sloppy and inefficient, because there were
>> standard constructions and solutions I just didn't know about.  I'd like
>> to
>> avoid that with Python.
>>
>>
> Welcome to the mailing list.  I expect you'll find Python a much cleaner
> language than the other two, though php has some definite convenience for
> its particular niche.
>
>
>
>
>  So:  my first two questions to the list.
>>
>> 1) Python 2.7 or 3.x?  I know I'm going to want to do some work with NLTK
>> (which appears to only have an alpha version out for Python 3), but I've
>> just gone through the hassle of dealing with an upgrade from PHP 4 to 5.3,
>> and I'd rather not start learning something that's already obsolete.  Any
>> words of advice?
>>
>>
> If you have to use a library that's not available yet for 3.x, then you
> need to use 2.x  on the other hand, if you're learning now, maybe that
> library will be available by the time you actually need it.
>
> For most people, I'd advise against trying to use a tutorial that targets
> a different version than you're running.  If you get frustrated quickly,
> you can get bogged down by the differences when you're just copying an
> exact program out of some book.
>
> Python 3 in particular has spent some substantial effort cleaning up the
> warts, the biggest one being Unicode.  For beginning programmers using only
> ASCII, probably the main thing that'll bog you down is that print() is now
> a function, rather than a statement, so you need parentheses. But once you
> get used to seeing syntax error, you quickly get the hang of it.  And once
> you do, the function is much nicer.
>
>
>
>  2) Best practices.  I have the WROX Press Beginning Python book, which
>> targets Python 2.  Clearly that's of only limited value if I'm going to go
>> with Python 3, but it looks like it's at least going to be a good
>> overview.
>>   But some of the stuff they do seems to be fairly personalized, rather
>> than
>> trying to follow standards.  Should I just start out with the tutorial
>> from
>> docs.python.org?  I would assume that that would start putting me in the
>> right habits from the beginning... is that accurate, or is there a better
>> way to go?
>>
>> Thanks in advance,
>>Andy McKenzie
>>
>
> I'd start with the python.org tutorial for the version you're trying to
> learn.  Get serious about trying everything, and don't try to absorb it all
> in one sitting, even though it can be done.
>
> And use a text editor that helps you indent, or even that colorizes your
> code.  And when you just want to try things, use the interpreter directly.
>  It's amazing what you can learn directly from it.  You can ask the
> interpreter lots of questions about an object:
>
>help(obj)
>dir(obj)
>print( type(obj) )
>print( repr(obj) )
>
> And don't forget to post here when you seem to be stuck.  Sometimes a well
> placed comment beats days of struggling.  When you do get an exception you
> don't understand, paste the whole thing, as well as the code you were
> trying.
>
> Best of luck.
>
>
>
>
Thanks for the advice, folks.  Given that it looks like the biggest changes
are unicode handling (which I'm not going to need any time soon) and the
way the print function works, I decided to stick with 2.7.  I'm an IT guy,
though unemployed at the moment, and it occurred to me that "I'm familiar
with Python, but not the version your entire established codebase is in"
wasn't a great thing to have on a resume.

Since it looks like the new formatting for print -- that is, print("Print
this stuff!") -- works fine in 2.7, I'm just getting myself used to doing
that from the beginning.

I went through the first four or five sections of the tutorial this
afternoon, with a few side trips into things that got me interested, and I
figure I'll do at least one more section after dinner.  I did find it
interesting that one of the first things I wanted to know turned out to

Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread Andy McKenzie
On Tue, Apr 16, 2013 at 5:31 PM, Dave Angel  wrote:

> On 04/16/2013 05:20 PM, Andy McKenzie wrote:
>
>>
>>
>>  
>
>
>>>
>>>  Thanks for the advice, folks.  Given that it looks like the biggest
>> changes
>> are unicode handling (which I'm not going to need any time soon) and the
>> way the print function works, I decided to stick with 2.7.  I'm an IT guy,
>> though unemployed at the moment, and it occurred to me that "I'm familiar
>> with Python, but not the version your entire established codebase is in"
>> wasn't a great thing to have on a resume.
>>
>> Since it looks like the new formatting for print -- that is, print("Print
>> this stuff!") -- works fine in 2.7, I'm just getting myself used to doing
>> that from the beginning.
>>
>>
> The degenerate print, where you're printing exactly one thing, works the
> same.  But if you have two things to print, putting parens around them in
> Python 2.x will cause a tuple to be printed, rather than printing the two
> with a space between.
>
> >>> print(3,5)  -- version 2.x
> (3, 5)
>
> >>> print(3,5)  -- version 3.x
> 3 5
>
> To get 3.x functionality, you'd want to use
> from __future__ import print_function
>
> and I do not think that works in 2.6 or older versions.  It also can be
> awkward even in 2.7 if you're mixing existing code with new print functions.
>
>
That's good to know, since I hadn't run into it yet.

So am I correct in understanding that I can just put the from __future__
import print_function in each new 2.7 script, and get identical
functionality to what happens in 3.x?  Or do I need to do that system-wide
somehow?

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


Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread Andy McKenzie
On Tue, Apr 16, 2013 at 7:39 PM, Alan Gauld wrote:

> On 16/04/13 22:20, Andy McKenzie wrote:
>
>  For instance:  output of running print_r on a very short dictionary from
>> PHP:
>>
>> Array
>> (
>>  [key3] => thing3
>>  [key2] => thing2
>>  [key1] => thing1
>> )
>>
>> And running pprint on the same dict in Python:
>>
>> {'key1': 'thing1', 'key2': 'thing2', 'key3': 'thing3'}
>>
>>
>> I finally decided that a good project would be building a quick function
>> that recreates the print_r function, and I got that working.  New
>> function output, in Python:
>>
>> (
>>  [key3] => thing3
>>  [key2] => thing2
>>  [key1] => thing1
>> )
>>
>
>
> You should probably use {} instead of () as the delimiter to indicate that
> the thing is a dictionary and not a tuple. but otherwise that's a good
> starter project.
>
>
Good idea.  I went with () because I was just trying to duplicate the
output in PHP.  Now that I've got that, I can start thinking about
improvements.  Varying the punctuation to match the type would probably be
a good idea.

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


Re: [Tutor] multiple versions of python on windows?

2013-04-22 Thread Andy McKenzie
I have no idea on Wing, but I'm using Eclipse with the PyDev plugin, and
I'm able to associate projects with either Python 2.7 or 3.2 in Windows.
 It checks for correct grammar in each, and if I tell it to run as a Python
script, it uses the correct executable.

So if you're not tied to Wing, you might give Eclipse/PyDev a try.

-Andy


On Mon, Apr 22, 2013 at 2:42 AM, Jim Mooney wrote:

> On 21 April 2013 22:47, School  wrote:
> > You can install multiple versions. The programs use the version they
> were assigned to, so there shouldn't be any conflict.
>
> This brings up the question of installing multiple versions of Wing
> 101 IDE. I forget the install but even if I can install in a different
> directory for Py 2.7, Windows awful Registry might trip me up. I've
> grown to love portables since they bypass Windows Worst Idea, but Wing
> isn't one of them.
>
> If anyone knows, does the paid version of wing allow to switch between
> multipe installs? I know, this is probably a Wing discuss question,
> but I'm burned out on joining discussion groups to ask one question,
> since otherwise Wing is very easy to grasp.
>
> --
> Jim Mooney
>
> Today is the day that would have been tomorrow if yesterday was today
> ___
> 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] Multiple search and replace?

2013-05-02 Thread Andy McKenzie
Hey folks,

  I'm trying to figure out how to do something, and it feels like it should
be possible, but I can't figure out how.  What I want is to define four
expressions, like so:

(\sNorth\s|\sN\s)(\sSouth\s|\sS\s)(\sEast\s|\sE\s)(\sWest\s|\sW\s)

And then run a replace such that the groups are replaced, in order, with "N
", "S ", "E ", or "W " (capital letters, no spaces before).

It's easy enough to use re.sub to replace ONE of those, and I could just do
that four times, but is there a way to do all at once?  It looks from some
things I've seen like it should be, but I can't figure out how.

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


Re: [Tutor] [OT] Replies go to individuals, not the list?

2013-08-20 Thread Andy McKenzie
On Mon, Aug 19, 2013 at 8:18 PM, Leam Hall  wrote:

> All,
>
> Am I more confused than normal or if I click "Reply" should it go just to
> the sender instead of the list?
>

Yep.  Someone decided it didn't make sense for "reply" to go to the list
that sent the message and should be receiving the reply.  I've never
understood it, even after reading the arguments in favor.

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


Re: [Tutor] [OT] Replies go to individuals, not the list?

2013-08-20 Thread Andy McKenzie
On Tue, Aug 20, 2013 at 2:53 PM, Alan Gauld wrote:

> On 20/08/13 13:15, Andy McKenzie wrote:
>
>  Yep.  Someone decided it didn't make sense for "reply" to go to the list
>> that sent the message
>>
>
> Lists never send messages. People do.
>
> So reply goes to the *person* who sent the message.
> Which is what mail always does, to modify it for mail
> forwarded by a list server makes no sense whatsoever.
> And it breaks the ability to send to the originator.
>
> IMHO of course :-)
> http://mail.python.org/mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>

The problem is, as far as I'm concerned the message came from the list.
Needing to go to the dropdown and select "Reply to all" is just one extra
movement, and it's one I have to make every single time I reply.  In all
honesty, I can't think of a single time that I've wanted to reply to just
the original sender:  that's the point of a mailing list, to have
conversations on it.  I've occasionally been prompted to remember that I
wanted to ask an individual something specific off-list, but it's never
been a direct response to what was posted ON the list.

As to the ability to send to the originator:  I've been on a lot of lists
where the address was munged.  They all included the original sender's
email address in the body, so if I really wanted to send to them, I could.
And the rest of the time (basically always) I didn't have to think about it.

It's basically a practicality thing for me.  On a list where the vast
majority of replies went to the original sender, I'd agree with you.  For
something like this, it's just making me do extra work without providing me
with an extra benefit.

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


Re: [Tutor] [OT] Replies go to individuals, not the list?

2013-08-20 Thread Andy McKenzie
leam hall wrote:

>
> > The only question I have is what is compelling about being different than
> > other lists? Far as I can tell, most reply to the list if you click
> reply.
> >
> > It's not something to get religious over; if I reply and don't have time
> to
> > make sure it goes to those who might be interested, at least it will go
> to
> > the person I'm responding to. They can forward it on if it's important
> > enough.  :)
> >
>
> Yeah, and top-posting with html mail is similarly taking the easy way
> out.  After all, who cares if everyone else has to put up with your bad
> habits.
>

Well, since someone else brought it up... I really prefer top posting.  In
general, I don't WANT to reread every message:  I want to quickly get to
whatever is new.  Top posting, much like the return-address munging
question, is a personal preference.  For me, it runs opposite to what this
list requires.  Clearly whoever set up this list agreed with you.

What REALLY gets to me is the people who try to insist that their way is
objectively RIGHT, and everyone else is practicing bad habits, or polluting
the net, or some other nonsense like that.  The fact is, we just have
different work flow preferences.  You like one thing, I like another.  If
you want to present your view rationally and objectively, or talk about
your preferred layouts, that's fine.  But let's not start saying someone
has "bad habits" because they disagree with you.

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


Re: [Tutor] global variables

2013-08-22 Thread Andy McKenzie
On Thu, Aug 22, 2013 at 10:12 AM, Matthew Ngaha  wrote:

> On Thu, Aug 22, 2013 at 2:52 PM, Chris Down  wrote:
> >I would doubt that anyone has told you "don't ever use classes", because
> > that's nonsense; you've probably misread a dissuasion from that path in a
> > single instance as applying more broadly than was intended.
>
> I am being totally honest here. I was very confused at the time and i
> said i didn't agree because it's what i had put so much effort into
> learning. They went on to say at some well known Python talks speakers
> have stated why using OOP (especially inheritance, but not excluding
> any others) is very bad design and the same thing can always be
> achieved without it. To be clear they said every use case OOP is the
> worst option. I asked what about GUIs which their design is strongly
> based around OOP? and they sad GUIs are badly designed to begin with
> so it proves the point about OOP.
>

OK, I'm not a fantastic programmer in any language, but this strikes me as
someone with an axe to grind giving bad advice to new programmers.  Here
are a few of the things that I see wrong with their statements:

1) For almost every option in programming, there's at least one case where
it's a good idea, design-wise.  Saying "in every use case OOP is the worst
option" is absurd.  Of course there are cases where it's not the worst
option.  There are also cases where it is.  That goes for just about
everything.

2) If they think OOP is always a bad idea, WHY are they using Python?
Isn't object orientation kind of the whole POINT of Python?  From python.org:
"Python is an interpreted, object-oriented, high-level programming language
with dynamic semantics."  If they honestly believe that object oriented
programming is always a bad idea, they really need to pick a different
language.  Perl, maybe, although even in Perl people are doing object
oriented work.  I have trouble believing that someone who believes OOP is
inherently bad is a current high-level programmer in Python, unless they're
trapped in a job they don't want to be doing.

3) Bad design in a product does not mean bad design in the tool used to
build it.  I've built some really terrible things out of wood with really
nice tools.  I've watched people use really nice drafting tools to design
houses that would have been unusable for living in.  Saying badly designed
GUIs prove that OOP is bad is, frankly, illogical at best and stupid at
worst.

I strongly suspect that either the speaker they were listening to wasn't
clear, or they weren't clear.  Either that, or the speaker or whoever you
were talking to mis-represented their ability level.

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


Re: [Tutor] Beginner Question

2013-10-22 Thread Andy McKenzie
On Tue, Oct 22, 2013 at 10:25 AM, Sven Hennig wrote:

> Hello, I would like to learn a programming language and have decided to
> use Python. I have some programming experience and doing well in Python.
> What really causes me problems is OOP.
> I'm just dont get it... I'm missing a really Practical example. In every
> book I've read are the examples of such Class Dog and the function is bark
> . Has anyone an OOP example for me as it is really used in real code, so
> I can better understand the concept? I do not know why this is so hard for
> me.
>
> Greetings
> Sven
>
>
The actual code I have is in PHP, so it's not exactly useful to post here,
but I can give you an outline of a class I used and found useful.  The
class was created to help me manipulate network subnets in an interface to
handle DHCP and DNS on a server.

class subnet:

   def __init__(cidr):
  # Do some stuff with the CIDR notation of the subnet (1.2.3.0/24syntax)

  def netmask:
 # Calculate the netmask and return it (ie, 255.255.255.0)

   def first_ip:
  # Calculate and return the first IP in the range.

   def last_ip:
  # Calculate and return the last IP in the range

   def number_of_addresses:
  # Calculate the number of usable addresses in the range and return
that value

The benefit to me was that I could create an instance of the subnet object
for a group (say, "lab_1"), and then pull out various information.  Calling
"lab_1.first_ip()" returns the first possible IP address.  That was a lot
more readable and a lot more concise than something like "first_ip(
1.2.3.0/24)".


I hope this helps!

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


Re: [Tutor] How to post: Was Re: The Charms of Gmail

2013-12-23 Thread Andy McKenzie
You know what?  I've been lurking here a long time.  I've asked a few
questions and gotten a few useful responses.

But overwhelmingly, when I think of this list, I find that my instinctive
response is "Full of rude, arrogant people."

So screw this.  I don't need to keep reading insults to people who are
trying to ask reasonable questions.  I don't need to read long rants about
how GMail is ruining the world and all its users ought to be banned.  I
don't need to watch people be harassed for daring to top-post.  There's at
least one post in every thread I read here that makes me think "This guy's
a jerk... why am I reading this?"

I'm done.  With the list, and possibly with Python... it doesn't seem to do
much that other languages I like don't do, and the loudest portion of the
language's advocates -- not the majority, just the loudest -- are just
plain obnoxious.  I don't need that in my life.

Good luck to all of you, and I hope your lives are pleasant.  And I hope
those of you who don't currently know learn how to treat people politely.

Andy McKenzie


On Mon, Dec 23, 2013 at 10:11 AM, Steven D'Aprano wrote:

> On Mon, Dec 23, 2013 at 12:59:15PM +, Mark Lawrence wrote:
>
> > I entirely agree.  I'll offer to supply the cotton wool, baby oil, bibs
> > and nappies that we can wrap the newbies up in
>
> "Wrap the newbies up in"? Who taught you to speak English? And what's
> with the two spaces after a full stop? It's not 1955 anymore, get with
> the program.
>
> (See how annoying it is to have the substance of your post completely
> ignored while trivial incidentals are picked on? Are you now even a
> *tiny* bit moved to use a single space after full stops?)
>
>
> > as we don't want to offend them.
>
> It's not about *offending* them. It's about being a tedious, shrill
> nagger that makes the whole environment unpleasant for everybody, not
> just the newbies. If you can give advice without being unpleasant and a
> nag, please do so. Would you rather be "right", and ignored, or
> effective?
>
>
> > I mean if we do offend them, they might desert us for
> > places such as stackoverflow, where they can read top voted answers that
> > are completely wrong.
>
> I keep hearing people say this about StackOverflow, but whenever I
> google on a question I find plenty of good answers there. Yes, I see
> some pretty wrong or silly or ignorant answers, but not as the top-voted
> answer. Can you show me some of these top-voted but wrong answers?
>
>
> --
> Steven
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Comparing two CSV filess using Python

2015-02-12 Thread andy van
Hi, I'm trying to compare two CSV files (and many more like these below). I
tried many ways, using lists, dictreader and more but nothing gave me the
output I require. I want to compare all those rows that have same
!Sample_title and !Sample_geo_accession values (whose positions vary). I've
been struggling with this for three days now and couldn't come to a
solution. I highly appreciate any help.

CSV1:

!Sample_title,!Sample_geo_accession,!Sample_status,!Sample_type,!Sample_source_name_ch1
body,GSM501443,Public on july 22 2010,ribonucleic acid,FB_50_12wk
foreign,GSM501445,Public on july 22 2010,ribonucleic acid,FB_0_12wk
HJCENV,GSM501446,Public on july 22 2010,ribonucleic acid,FB_50_12wk
AsDW,GSM501444,Public on july 22 2010,ribonucleic acid,FB_0_12wk

CSV2:

!Sample_title,!Sample_type,!Sample_source_name_ch1,!Sample_geo_accession
AsDW,ribonucleic acid,FB_0,GSM501444
foreign,ribonucleic acid,FB,GSM501449
HJCENV,RNA,12wk,GSM501446

Desired output (with respect to CSV2):

Added:
{!Sample_status:{HJCENV:Public on july 22 2010,AsDW:Public on july 22
2010}} #Added columns, not rows.

Deleted:
{} #Since nothing's deleted with respect to CSV2

Changed:

{!Sample_title:AsDW,!Sample_source_name_ch1:(FB_0_12wk,FB_0),!Sample_geo_accession:GSM501444
!Sample_title:HJCENV,!Sample_type:(ribonucleic
acid,RNA),!Sample_source_name_ch1:(FB_50_12wk,12wk),!Sample_geo_accession:GSM501446}
#foreign,ribonucleic acid,FB,GSM501449 doesn't come here since the
!Sample_geo_accession column value didn't match.

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


[Tutor] Condensed python2.5 cheat sheet

2007-12-19 Thread Samm and Andy
Hi people,

I've a competent programmer friend who I'm trying to convert to the ways 
of python and I was wondering if people could recommend a decent cheat 
sheet for python 2.5.
He know how to program but just needs the syntax to become pythonic

Thanks

Andy

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor