Re: [Tutor] New to Python..Need help

2014-09-04 Thread taserian
Is there anything different between the filenames aside from that suffix
_vXX? If not, then you'll run into problems after the first filename is
changed; further attempts won't allow the change, since there's already a
file with that same name.

AR


On Thu, Sep 4, 2014 at 8:49 AM, Felisha Lawrence  wrote:

> Hello,
> I have a question regarding strings in python. I have a directory on my
> MacBook Bro of about 13 files. I need to alter the file endings in
> that directory. The files are on the order of
> 'swp.113006004000_KLWX_0.0.5_PPI_v2','swp.113006004000_KLWX_0.0.5_PPI_v3'.
> I need to remove the characters after the 'v' and replace with v20. All of
> the endings of the files are sequential _v2, _v3,_v4, _v5. I need all of
> these characters to be the same (i.e. v20). I would like to know which
> modules are best to use, and how to use loops to alter them. Any help you
> can provide would be great.
>
>
> Thanks,
> Felisha Lawrence
>
> --
> Felisha Lawrence
> Howard University Program for Atmospheric Sciences(HUPAS), Graduate
> Student
> NASA URC/BCCSO Graduate Fellow
> NOAA NCAS Graduate Fellow
> Graduate Student Association for Atmospheric Sciences(GSAAS), Treasurer
> (240)-535-6665 (cell)
> felisha.lawre...@gmail.com (email)
>
> ___
> 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] Keeping change-in-place vs. copy methods straight

2014-04-28 Thread taserian
I can't claim to be new to programming, but I've dabbled in Python over and
over again to get small problems and puzzles resolved. One thing that I
find I can't keep straight are the methods that change a list in place, vs.
those that return a copy (sometimes transformed) of the list.

Call me old-fashioned, but my programming experience mostly comes from
languages where you assigned the output of a function to another variable,
so you always had a copy of whatever you were working on.

var array;
sorted = array.sort();

If you didn't care to keep both copies, you could always re-assign the
returned value to the original variable.

array = array.sort();

If I try to do the same in Python:

sorted = arrayList.sort()

sorted comes back as None, while arrayList has changed its order.

Is there some sort of rule-of-thumb to determine if a function is in-place
or returns a value?

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


[Tutor] Comparison Textboxes

2013-08-26 Thread taserian
I'm attempting to gather the pieces I need for a simple project I'd like to
do for my job, but I'm having a difficult time finding something, and I'm
appealing to the hive mind at Tutor for wisdom.

My project needs to compare two or more large textboxes (each one
containing a file or a large amount of text) and point out their
differences, establishing one textbox as the canonical one to which the
other textboxes are compared. This functionality is done in many text
editors (Notepad++ can install a plug-in that allows comparison between two
files), so I would think that the code behind this is pretty common, yet I
can't seem to find any reference to it. My searches for "python text
comparison code" points to Python IDEs that include that functionality, but
no indication as to how to include it into my own code. I think I'm missing
something else to search by, but I can't determine what it is.

Does anyone have an idea of what I'm talking about, and can you point me in
the right direction?

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


Re: [Tutor] Python help!!

2013-04-02 Thread taserian
On Tue, Apr 2, 2013 at 12:49 PM, David Mitchell wrote:

> Hi!
>
> How do I go through a text file, finding specific words/numbers/phrases
> and edit them to say different things? I do not want to edit the text file,
> I would rather open and read from the text file and write to a new file.
>
> I do NOT want to know how to replace a specific word with another every
> time it appears. There are some "OFF" 's that i would like to change to
> "ON" 's and some that I would like to change to "OPEN" for example.
>

How would you know which ones to change to "ON" and which ones to change to
"OPEN"? Additionally, how would you describe those conditions in Python?


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


Re: [Tutor] Text Processing Query

2013-03-14 Thread taserian
Since the identifier and the item that you want to keep are on different
lines, you'll need to set a "flag".

with open(filename) as file:

scanfile=file.readlines()

flag = 0

for line in scanfile:

if line[0:6]=='COMPND' and 'FAB FRAGMENT' in line: flag = 1

elif line[0:6]=='COMPND' and 'CHAIN' in line and flag = 1:

print line

flag = 0


Notice that the flag is set to 1 only on "FAB FRAGMENT", and it's reset to
0 after the next "CHAIN" line that follows the "FAB FRAGMENT" line.


AR


On Thu, Mar 14, 2013 at 6:56 AM, Spyros Charonis wrote:

> Hello Pythoners,
>
> I am trying to extract certain fields from a file that whose text looks
> like this:
>
> COMPND   2 MOLECULE: POTASSIUM CHANNEL SUBFAMILY K MEMBER 4;
>
> COMPND   3 CHAIN: A, B;
>
> COMPND  10 MOL_ID: 2;
>
> COMPND  11 MOLECULE: ANTIBODY FAB FRAGMENT LIGHT CHAIN;
>
> COMPND  12 CHAIN: D, F;
>
> COMPND  13 ENGINEERED: YES;
>
> COMPND  14 MOL_ID: 3;
>
> COMPND  15 MOLECULE: ANTIBODY FAB FRAGMENT HEAVY CHAIN;
>
> COMPND  16 CHAIN: E, G;
>
> I would like the chain IDs, but only those following the text heading
> "ANTIBODY FAB FRAGMENT", i.e. I need to create a list with D,F,E,G  which
> excludes A,B which have a non-antibody text heading. I am using the
> following syntax:
>
> with open(filename) as file:
>
> scanfile=file.readlines()
>
> for line in scanfile:
>
> if line[0:6]=='COMPND' and 'FAB FRAGMENT' in line: continue
>
> elif line[0:6]=='COMPND' and 'CHAIN' in line:
>
> print line
>
> But this yields:
>
> COMPND   3 CHAIN: A, B;
>
> COMPND  12 CHAIN: D, F;
>
> COMPND  16 CHAIN: E, G;
>
> I would like to ignore the first line since A,B correspond to non-antibody
> text headings, and instead want to extract only D,F & E,G whose text
> headings are specified as antibody fragments.
>
> Many thanks,
> Spyros
>
>
>
>
> ___
> 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] Extracting columns from many files to different files

2012-07-16 Thread taserian
On Mon, Jul 16, 2012 at 10:58 AM, susana moreno colomer <
susana...@hotmail.com> wrote:

>  Hi!
> I have a folder, with the following text files with columns:
>
> bb_ 1
> bb_2
> ww_1
> ww_2
> ff_1
> ff_2
>
> What I want to do is:
>
>- Extract columns 5,6, 8 from files bb_
>- Extract columns 3,4 from files ww_
>- Get 5 files, corresponding to different columns:
>- Files (excel files): 'ro' with colums number 5,  'bf' with colums
>number 6,  'sm' with column 8,  'se' with columns number 3 and  'dse' with
>columns number 4
>
> How are these columns separated? Blank spaces, tabs, commas?

I'm mostly worried about:

for b in line:
A.append(b[5].strip())
B.append(b[6].strip())
C.append(b[8].strip())

For the A List, this will take the 5th character from the line, not the 5th
column. You may need to split the line based on the separators.

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


Re: [Tutor] Generating random alphanumeric codes

2012-06-26 Thread taserian
Correcting what was said below.

- If not, then it's a little more complicated, calculate (length) *
(length-1) * (length-2) * (length-3), or in other words the factorial of
length divided by the factorial of (length - 4). In my example, 62! /
(62-4)! = 13,388,280

On Tue, Jun 26, 2012 at 11:08 AM, taserian  wrote:

> First of all, determine your alphabet (the pool of characters you'll
> derive your 4-character code from):
>
> - For example, using an English alphabet with both lowercase and uppercase
> letters and digits 0-9 makes for 62 characters (26 + 26 + 10).
>
> Then, ask if you want to allow a character to repeat itself in the
> 4-character code.
>
> - If so, then it's easy: take the length of your alphabet, and calculate
> (length)^4. In my example above, it would be 62^4 = 14,776,336
>
> - If not, then it's a little more complicated, calculate (length) *
> (length-1) * (length-2) * (length-3), or in other words the factorial of
> length minus the factorial of (length - 4). In my example, 62! - (62-4)! =
> 13,388,280
>
> AR
>
> On Tue, Jun 26, 2012 at 10:52 AM, Sithembewena Lloyd Dube <
> zebr...@gmail.com> wrote:
>
>> HI,
>>
>> Would anyone have tips on how to generate random 4-digit alphanumeric
>> codes in python? Also, how does one calculate the number of possible
>> combinations?
>>
>> Thanks in advance.
>>
>> --
>> Regards,
>> Sithembewena Lloyd Dube
>>
>> ___
>> 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] Generating random alphanumeric codes

2012-06-26 Thread taserian
First of all, determine your alphabet (the pool of characters you'll derive
your 4-character code from):

- For example, using an English alphabet with both lowercase and uppercase
letters and digits 0-9 makes for 62 characters (26 + 26 + 10).

Then, ask if you want to allow a character to repeat itself in the
4-character code.

- If so, then it's easy: take the length of your alphabet, and calculate
(length)^4. In my example above, it would be 62^4 = 14,776,336

- If not, then it's a little more complicated, calculate (length) *
(length-1) * (length-2) * (length-3), or in other words the factorial of
length minus the factorial of (length - 4). In my example, 62! - (62-4)! =
13,388,280

AR

On Tue, Jun 26, 2012 at 10:52 AM, Sithembewena Lloyd Dube  wrote:

> HI,
>
> Would anyone have tips on how to generate random 4-digit alphanumeric
> codes in python? Also, how does one calculate the number of possible
> combinations?
>
> Thanks in advance.
>
> --
> Regards,
> Sithembewena Lloyd Dube
>
> ___
> 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] Python program with multiple answers

2011-05-11 Thread taserian
In addition to the wise counsel you've already received, I noticed that your
randint goes from 0 to 10, but you have 20 possible outcomes in dice(). If
I'm counting correctly, it should be roll=random.randint(0, 19).

Tony R.

On Wed, May 11, 2011 at 6:49 AM, Johnson Tran  wrote:

> Hi Guys,
>
> I've been working on a Python program where I create an 8 ball that will
> allow you to ask questions and will reply back with 20 possible answers. It
> will be continuous until the user says quit. My program works fine although
> I am trying to add something more to it, where when the user quits, it will
> present all the answers that the user got again and display them in
> alphabetical order...if anyone could point me in the right direction it'd be
> really helpful...my program so far is : (which works fine with no errros)
>
>
>
> import random
> dice = ("Without a doubt", "It is certain", "It is decidedly so","Yes",
> "For Sure", "No", "Dont count on it", "Try asking again","Reply hazy, try
> again", "Confucious says 'No'", "Better not tell you now","Cannot predict
> now","Concentrate and ask again","My reply is no","Outlook not so
> good","Very doubtful","Outlook is good","Most likely","As I see it, yes","I
> do not understand the question")
> while True:
>choice = raw_input("Type 'ask' to ask a question. Type 'quit' to
> quit.\n")
>if choice == "ask":
>raw_input("Please enter your question:\n")
>roll = random.randint(0, 10)
>print dice[roll]
>raw_input()
>elif choice == "quit":
>True = 0
>raw_input()
>else:
>print "Error -- Try again\n"
>
>
>
>
>
> Thanks,
>
> JT
>
> ___
> 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] Checksum program

2011-03-23 Thread taserian
On Wed, Mar 23, 2011 at 11:11 AM, Lezlie Kline wrote:

> I have a question for the list about the homework rule and the tutoring
> list.  If you have a question and you're not asking for your homework or
> past homework to be done for you but you just have questions to be explained
> isn't that what tutoring and learning is all about.  For example, on my
> question here.  I have a problem that is not homework for a grade and I
> don't understand it.  I can't find a tutor.  I'm frustrated and you guys can
> provide help for my understanding which you were doing.  Not by giving me an
> answer, but by asking me questions and helping me to understand.  Isn't that
> what tutoring and open forum is all about.  Unfortunately, I still don't
> quite have it I feel like I got left hanging on the edge of almost...
>
I tend to err on the side of caution and try not to give away too much, just
so that the student achieves more by themselves than by giving them the
answer outright. What's the quandary on that "edge of almost"?


> I called the Dean of Graduate students at NC State to try to find someone
> to tutor me and the response was helpful but Python isn't taught at NC
> State.  UNC - the same.  Wake Technical - the same.  I've looked on Craig's
> list and Googled with no luck  I'm taking an intro to computer science class
> online through Utica for Cybersecurity and I would just like some help
> understanding.  I'm not one to easily give up!!
>
> Anyway, I understand having rules and why, but I also think that when those
> rules don't make sense under the situation exceptions should be made.  Just
> saying...
>
> L.


Have you tried any of the online Python tutorials?

http://docs.python.org/tutorial/

http://heather.cs.ucdavis.edu/~matloff/Python/PythonIntro.pdf

http://www.freenetpages.co.uk/hp/alan.gauld/

Even though Python has been around long enough, it isn't taught formally in
as many institutions as we'd like. I'd venture to guess that most of the
Python experts on this list are self-taught rather than having taken a
formal course. The above links would be great for you if you're up for
learning on your own.

One thing I've found: http://trizpug.org/ , which seems to be a Python group
that meets monthly in the Durham area (not sure how close that is to you).
You might want to subscribe to their mailing list and see if there's anyone
willing to tutor you, if that's more your style; it looks like they have a
meeting tomorrow 3/24/11. I'd contact them and see how welcome they are to
newcomers.

Hoping this helps,

Tony R.



>  On Wed, Mar 23, 2011 at 10:54 AM, taserian  wrote:
>
>> When replying to the Python Tutor list, please use "Reply All" instead of
>> just "Reply". I meant to put this in my previous message, but it remained in
>> "meant to" phase and never got implemented properly. 8-)
>>
>>
>>  I don't think it's been initialized properly, but that's where I don't
>> understand about the accumulator for strings.  I originally thought this for
>> the accumulator:
>>
>> output=""
>> for i in range(len(message[i])"
>>
>>
>>>>> print"The value of message[i] is ", message[i]
>>>>> output=output+" " + ord(message[i])
>>>>>
>>>>> print"The value of the message is ", output
>>>>>
>>>>> but strings and integers don't concatentate AND my ord(value) isn't
>>>>> accumulating AND I thing my output is getting overwritten.
>>>>>
>>>> You don't want to mix apples and oranges. Your variable "message"
>>>> contains a full name in the test case, "John X. Doe", for example, so it's
>>>> made up of characters. What should the accumulator contain, if you're going
>>>> to be adding numbers? Numbers
>>>>
>>>
>> Then your code above should look something like this:
>>
>> output= 0
>> for i in message:
>> print"Character i in message: ", message[i]
>>
>> output=output + ord(message[i])
>>  print "The value of the message is ", output
>>
>>
>> In pseudocode:
>> Start with the value for an empty message in the variable "output".
>> For every character in "message":
>> Print the character
>> Add the ASCII value of the character to the accumulator "output".
>> After all of the characters have been processed, show the final value of
>> "output"
>>
>>
>>>
>>>> Is this homework? Not anymore  I'm past that and I live in NC and I've
>>>> been desperately looking for a tutor but I'm having difficulty finding
>>>> anyone who does Python programming.  They don't teach it at NC State or UNC
>>>> or Wake Tech.  If you don't want to help.  I understand.  This was my last
>>>> resort.
>>>>
>>>
>>>>
>>>
>> Not at all. It's just that we have a rule about not doing
>> anyone's homework on the list. It robs them of the learning experience, and
>> can provide a grade which hasn't been earned properly.
>>
>> Tony R.
>>
>>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Checksum program

2011-03-23 Thread taserian
When replying to the Python Tutor list, please use "Reply All" instead of
just "Reply". I meant to put this in my previous message, but it remained in
"meant to" phase and never got implemented properly. 8-)

 I don't think it's been initialized properly, but that's where I don't
understand about the accumulator for strings.  I originally thought this for
the accumulator:

output=""
for i in range(len(message[i])"


>>> print"The value of message[i] is ", message[i]
>>> output=output+" " + ord(message[i])
>>>
>>> print"The value of the message is ", output
>>>
>>> but strings and integers don't concatentate AND my ord(value) isn't
>>> accumulating AND I thing my output is getting overwritten.
>>>
>> You don't want to mix apples and oranges. Your variable "message"
>> contains a full name in the test case, "John X. Doe", for example, so it's
>> made up of characters. What should the accumulator contain, if you're going
>> to be adding numbers? Numbers
>>
>
Then your code above should look something like this:

output= 0
for i in message:
print"Character i in message: ", message[i]
output=output + ord(message[i])
print "The value of the message is ", output


In pseudocode:
Start with the value for an empty message in the variable "output".
For every character in "message":
Print the character
Add the ASCII value of the character to the accumulator "output".
After all of the characters have been processed, show the final value of
"output"


>
>> Is this homework? Not anymore  I'm past that and I live in NC and I've
>> been desperately looking for a tutor but I'm having difficulty finding
>> anyone who does Python programming.  They don't teach it at NC State or UNC
>> or Wake Tech.  If you don't want to help.  I understand.  This was my last
>> resort.
>>
>
>>
>
Not at all. It's just that we have a rule about not doing anyone's homework
on the list. It robs them of the learning experience, and can provide a
grade which hasn't been earned properly.

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


Re: [Tutor] Checksum program

2011-03-23 Thread taserian
On Wed, Mar 23, 2011 at 9:55 AM, Lezlie Kline wrote:

> Tony,
>
> For your question "What's the checksum for a completely empty message
> (i.e., no characters at all)?" Do you mean the value or how do I write it?
> I would think the value would be 0.
>
Correct. Now think of that as your starting point; any message containing
characters is going to start at 0 plus the sum of the ASCII values of each
of its characters. Where would you store the initial value of an empty
message?


> My understanding of where I'm storing the ASCII values for each letter is
> ord(message[i])
>
ord isn't a variable, it's a function. It's calculating the ASCII value of
the i-th character of "message".


> I don't think it's been initialized properly, but that's where I don't
> understand about the accumulator for strings.  I originally thought this for
> the accumulator:
>
> output=""
> for i in range(len(message[i])"
>
> print"The value of message[i] is ", message[i]
> output=output+" " + ord(message[i])
>
> print"The value of the message is ", output
>
> but strings and integers don't concatentate AND my ord(value) isn't
> accumulating AND I thing my output is getting overwritten.
>
You don't want to mix apples and oranges. Your variable "message" contains a
full name in the test case, "John X. Doe", for example, so it's made up of
characters. What should the accumulator contain, if you're going to be
adding numbers?


> Here's part of the problem.  The person "teaching" me Python provides some
> information and then jumps to the programs so I'm struggling in the fuzzy
> dark.  I was given the range "for i in range(len(message[i]):print"The value
> of message[i] is ", message[i]"  and I understand that it obtains the length
> of my message, but I don't really understand the [i] part other than [i]
> represents integer and the "i" in for i is the iteration of the loop so when
> you ask the question "message[i] will provide you the character at position
> i. What are you doing with it?" I'm not sure what you're asking?
>
> I'm sorry to be so dense.  Believe it or not I've been working on this
> program for a week
>
> L.


Is this homework?

Tony R.


>  On Wed, Mar 23, 2011 at 9:30 AM, taserian  wrote:
>
>>  On Wed, Mar 23, 2011 at 9:09 AM, Lezlie Kline wrote:
>>
>>> Hi,
>>>
>>> I'm trying to work out the bugs in a program for calculating the checksum
>>> (modulo 256) of an input string.  I'm testing it with my full name and I'm a
>>> beginner with Python.  Here's what I have so far.
>>>
>>> def main():
>>> print"This program creates a checksum for a message."
>>> name=raw_input("Please enter the message to encode: ")
>>> message=name
>>> output=name
>>> for i in range(len(message)):
>>> print"The value of message[i] is ", message[i]
>>> output=output+name+ord(message[i])
>>> print"The value of the message is ", output
>>> checksum=(output)%256
>>> print"The checksum is ", checksum
>>>
>>> main()
>>>
>> I'd like to give you some pointers so you can solve it yourself:
>>
>> What's the checksum for a completely empty message (i.e., no characters at
>> all)?
>> Where are you storing the (ASCII) values of each letter? Has it been
>> initialized properly?
>>
>>
>>> I know I'm offbase somewhere, but I'm not understanding some parts of the
>>> accumulator part of the program.  I need it to work with the message[i]
>>> intact.  In other words, I need the pseudo code to go something like this:
>>>
>>> print message
>>> get input
>>> find length
>>> using length in range function accumulate ASCII numbers
>>> calculate checksum
>>> print checksum
>>>
>>> I'd appreciate any help offered as I'm "pulling out my hair."
>>
>>
>> message[i] will provide you the character at position i. What are you
>> doing with it?
>>
>> Tony R.
>>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Checksum program

2011-03-23 Thread taserian
On Wed, Mar 23, 2011 at 9:09 AM, Lezlie Kline wrote:

> Hi,
>
> I'm trying to work out the bugs in a program for calculating the checksum
> (modulo 256) of an input string.  I'm testing it with my full name and I'm a
> beginner with Python.  Here's what I have so far.
>
> def main():
> print"This program creates a checksum for a message."
> name=raw_input("Please enter the message to encode: ")
> message=name
> output=name
> for i in range(len(message)):
> print"The value of message[i] is ", message[i]
> output=output+name+ord(message[i])
> print"The value of the message is ", output
> checksum=(output)%256
> print"The checksum is ", checksum
>
> main()
>
I'd like to give you some pointers so you can solve it yourself:

What's the checksum for a completely empty message (i.e., no characters at
all)?
Where are you storing the (ASCII) values of each letter? Has it been
initialized properly?


> I know I'm offbase somewhere, but I'm not understanding some parts of the
> accumulator part of the program.  I need it to work with the message[i]
> intact.  In other words, I need the pseudo code to go something like this:
>
> print message
> get input
> find length
> using length in range function accumulate ASCII numbers
> calculate checksum
> print checksum
>
> I'd appreciate any help offered as I'm "pulling out my hair."


message[i] will provide you the character at position i. What are you doing
with it?

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


Re: [Tutor] PYTHON QUOTES ISSUE

2010-10-08 Thread taserian
On Fri, Oct 8, 2010 at 10:27 AM, Susana Iraiis Delgado Rodriguez <
susana.delgad...@utzmg.edu.mx> wrote:

> Hi Alan:
>
> The ouput is coming from a cicle and some functions that I vae to do to
> execute an ogr2ogr command, in this output I ask the user for the name of a
> file and then make a module to get to the subprocess part:
>




> ##Eliminate duplicate lines from the txt into a new txt, status:100%
>   a = open ("capas.txt","r")
>   catalogo = open ("unico.txt","w")
>   unique = set(a.read().split("\n"))
>   catalogo.write("".join([line + "\n" for line in unique]))
>   catalogo.close()
>   a.close()
>

I don't see how this is eliminating duplicate lines. To me it looks like
it's just copying the contents of capas.txt into unico.txt and adding extra
\n (line breaks), which might be what's breaking your next line.


>
> ##Execute ogr2ogr command, status:75%
>  for line in open("unico.txt", "r"):
> p = subprocess.Popen(['C:/Archivos de
> programa/FWTools2.4.7/bin/ogr2ogr', line+'.shp', '-where',
> "\"LAYER='"+line+"'\"" , b+'.shp'])
>
> But when I executed it shows me an error in the layer's name:
>
> >>> ERROR 1: Failed to identify field:LAYER=
> ERROR 1: Failed to create file .shp file.
> ERROR 4: Failed to open Shapefile `0
> .shp'.
>
> I think the erros showed up because some of the layer's values are 0 and '
> ', and obsviously you can't create a file from nothing on it. But I don`t
> know how to validate if a layer's value is equals to 0 or ' ', any idea what
> I'm doing wrong or how to fix it?
>

Also, in your next e-mail, I noticed you're getting carriage returns (line
breaks in your output). Since you're adding those line breaks above, you
want to remove them before using them somewhere else.

p = subprocess.Popen(['C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr',
line.replace("\n", "") +'.shp', '-where', "\"LAYER='"+ line.replace("\n",
"") +"'\"" , b+'.shp'])


In the code above, I've changed the references to the variable *line* so
that the \n's are replaced by 0-length strings. That should remove them from
the Popen arguments.

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


Re: [Tutor] PYTHON QUOTES ISSUE

2010-10-07 Thread taserian
On Thu, Oct 7, 2010 at 12:48 PM, taserian  wrote:

> I'm adding some line breaks to make your text a little more readable.
>
> On Thu, Oct 7, 2010 at 9:55 AM, Susana Iraiis Delgado Rodriguez <
> susana.delgad...@utzmg.edu.mx> wrote:
>
>  Hello members:
>>
>> How can I write a statement to execute the following:
>>
>
>
>> C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr R1G-GEODESIA.shp -where
>> "LAYER = 'R1G-GEODESIA'" tapalpa_05_plani_point.dbf
>>
>
>
>> I want my uotput to look like this.
>> Instead I'm getting this
>>
>
>
>> C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr T21-PUENTES.shp -where
>> LAYER=+line tapalpa_05_plani_line.shp
>>
>
>
>> In miy code line is a string given by the user:
>>
>> for line in open("unico.txt", "r").readlines():
>>  p = subprocess.Popen(['C:/Archivos de
>> programa/FWTools2.4.7/bin/ogr2ogr', line+'.shp', '-where', "LAYER='line'",
>> b+'.shp'])
>>
>> Any suggestions?
>>
>
> Without knowing specifics about what the subprocess.Popen function is
> expecting as parameters, I can only speculate, but it seems that the
> following *might* work (for extremely generous values of "*might*"):
>
> for line in open("unico.txt", "r").readlines():
>  p = subprocess.Popen(['C:/Archivos de
> programa/FWTools2.4.7/bin/ogr2ogr', line+'.shp', '-where', "\"LAYER='" +
> line + "'\"", b+'.shp'])
>
> Details about where the changes are:
> "\"LAYER='" + line + "'\""
>

Begin corrections (corrections start with a *)

Quote to begin the literal: "
> An escaped quote (1) so that there's a quote inside the literal: \"
> Some of the text that's meant to be unchanging: LAYER=
>
*Single Quote (2) to be included in the literal (which doesn't need to be
escaped): '

> Close Quote: "
>
Add the content of the variable "line" from the unico.txt file:  + line +
>
*Add another literal, composed of the single quote that closes (2) above,
then the closing escaped quote to close (1) : "'\""


>
> See if this works, and let us know how it turns out.
>
> Antonio Rodriguez
>

End of corrections.

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


Re: [Tutor] PYTHON QUOTES ISSUE

2010-10-07 Thread taserian
I'm adding some line breaks to make your text a little more readable.

On Thu, Oct 7, 2010 at 9:55 AM, Susana Iraiis Delgado Rodriguez <
susana.delgad...@utzmg.edu.mx> wrote:

> Hello members:
>
> How can I write a statement to execute the following:
>


> C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr R1G-GEODESIA.shp -where
> "LAYER = 'R1G-GEODESIA'" tapalpa_05_plani_point.dbf
>


> I want my uotput to look like this.
> Instead I'm getting this
>


> C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr T21-PUENTES.shp -where
> LAYER=+line tapalpa_05_plani_line.shp
>


> In miy code line is a string given by the user:
>
> for line in open("unico.txt", "r").readlines():
>  p = subprocess.Popen(['C:/Archivos de
> programa/FWTools2.4.7/bin/ogr2ogr', line+'.shp', '-where', "LAYER='line'",
> b+'.shp'])
>
> Any suggestions?
>

Without knowing specifics about what the subprocess.Popen function is
expecting as parameters, I can only speculate, but it seems that the
following *might* work (for extremely generous values of "*might*"):

for line in open("unico.txt", "r").readlines():
 p = subprocess.Popen(['C:/Archivos de
programa/FWTools2.4.7/bin/ogr2ogr', line+'.shp', '-where', "\"LAYER='" +
line + "'\"", b+'.shp'])

Details about where the changes are:
"\"LAYER='" + line + "'\""

Quote to begin the literal: "
An escaped quote (1) so that there's a quote inside the literal: \"
Some of the text that's meant to be unchanging: LAYER="
Close Quote: "
Add the content of the variable "line" from the unico.txt file:  + line +
Add another literal, composed of just the closing escaped quote to close the
quote above (1) : "\""

See if this works, and let us know how it turns out.

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


Re: [Tutor] question about for loops

2010-01-07 Thread taserian
On Thu, Jan 7, 2010 at 7:43 AM, Richard D. Moores wrote:

> On p. 162 of "Programming In Python", 2nd ed., by Summerfield, the
> section entitled "for Loops" begins:
>
> =
> for expression in iterable:
> for_suite
> else:
> else_suite
>
> The expression is normally either a single variable or a sequence of
> variables, usually in the form of a tuple. If a tuple or list is used
> for the expression, each item is unpacked into the expression's items.
> ==
>
> I thought I was quite familiar with for loops, but I don't understand
> how the expression can be a sequence of variables, nor what  unpacking
> into the expression's items means. Could someone explain this,
> preferably with an example?
>
> Thanks,
>
> Dick Moores
>
>
As an example, think of a list of tuples, similar to the following:

tuplelist = [ (1, "a"), (2, "b"), (3, "c") ]

To process them and handle each tuples elements individually, you can have
the for statement:

for (a, b) in tuplelist:
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] GUI recommendations/tutorials?

2009-06-10 Thread taserian
I think I'm ready to start working with some simple graphic output.
Currently, I've got the basics of a Python program that calculates full
tours of a honeycomb structure, going through each cell exactly once. The
output from the program shows the paths as coordinates of each cell; what
I'd like to do is create a simple window that would show the tour in
graphical format, and using keystrokes to go through all of the tours that
have been collected. I'm already accounting for eliminating duplicates by
rotational symmetry by restricting the starting point to the cells in the
"northernmost" row of hexes, but the ending point to be any of the edge
hexes. I'm trying to identify duplicates by reflexive symmetries as well,
but I'd like to get the visualization component up first.

My problem is that I have no GUI experience outside of Visual Studio-style
drag-and-drop IDEs. Which Python GUI system would you recommend for
neophytes that would allow line drawing and a simple graphic load of a
honeycomb structure in a JPG, for example, as a background?

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


Re: [Tutor] improving the speed of prime number code

2009-02-06 Thread taserian
One potential way to speed up is not to divide by every prime in your pz
list, but only up to the square root of i.

For example, to test if 37 is prime, you would only need to look at primes
less than or equal to int(sqrt(37)) = 6.08. . .

Tony R.

On Fri, Feb 6, 2009 at 4:19 PM, H.G. le Roy  wrote:

> Hi,
>
> I'm stuck with Problem 10 (
> http://projecteuler.net/index.php?section=problems&id=10) :-)
>
> A part of my code deals with the calculation of prime numbers. However it
> is really slow. Hopefully you have some ideas how to make it faster.
>
> pz = [2]
> # only iterate over odd numbers
> for i in xrange(3,200,2):
>   remprod = 1  # product of remainders
>   for j in xrange(len(pz)):
> remprod *= (i % pz[j])
> if remprod == 0:  # if a number is divisible wo remainder its not prime
>   break
>   if remprod > 0:
> pz.append(i)
>
> ___
> 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] Coin Flip

2008-10-03 Thread taserian
Since the variable *count* never increases inside of the loop body, it gets
stuck in the *while* loop.

I recommend taking a hard look at the program, consider what it should be
doing, and then seeing which statements should be in the *while* loop, and
which ones should be outside it.

Tony R.

On Fri, Oct 3, 2008 at 2:04 PM, realNewbie <[EMAIL PROTECTED]> wrote:

>
> This is a class assignment, I am to create a program that flips a coin 100
> times and tells me the number of heads and tails.
> I've been working on it for 2 days now and I am stuck. I a trying to run
> the
> program but it is not running.
> Can someone please point out my error?
>
> Here is what I have come up with:
> import random
> heads=0
> tails=0
> count=1
> while count <101:
>   randomFlip = random.randrange(0,1)
> if randomFlip == 0:
>heads = heads + 1
> else:
>tails = tails + 1
> count = count + 1
> print heads," heads"
> print tails," tails"
> --
> View this message in context:
> http://www.nabble.com/Coin-Flip-tp19802888p19802888.html
> Sent from the Python - tutor mailing list archive at Nabble.com.
>
> ___
> 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] Randomize SSN value in field

2008-05-22 Thread taserian
On Thu, May 22, 2008 at 12:14 PM, GTXY20 <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I will be dealing with an address list where I might have the following:
>
> Name SSN
> John 1
> John 1
> Jane 2
> Jill 3
>
> What I need to do is parse the address list and then create a unique random
> unidentifiable value for the SSN field like so:
>
> Name SSNrandomvalue
> John 1a1b1c1d1
> John 1a1b1c1d1
> Jane 2a2b2c2d2
> Jill 3a3b3c3d3
>
> The unique random value does not have to follow this convention but it needs
> to be unique so that I can relate it back to the original SSN when needed.
> As opposed to using the random module I was thinking that it would be better
> to use either sha or md5. Just curious as to thoughts on the correct
> approach.
>
> Thank you in advance.
>
> G.

Both SHA and MD5 are intended to be one-way functions, such that you
can't recover what you provide as an argument. For example (taken from
http://www.python.org/doc/current/lib/module-hashlib.html) :

>>> hashlib.sha224("Nobody inspects the spammish repetition").hexdigest()
'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2'

There's no way to take the value 'a4337...' and return "Nobody
insp..", because there are potentially infinite strings that have to
map into the available 224-bit space that sha224 provides.

If you want to be able to recover the SSN, you should probably look at
cryptography. Here's a link that might interest you:
http://www.amk.ca/python/code/crypto.html

Tony R.
aka Taser
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newb Learning Question

2008-04-02 Thread taserian
On Wed, Apr 2, 2008 at 12:50 PM, Jeffrey Dates <[EMAIL PROTECTED]> wrote:

> Sorry forgot to post what I had so far:
>
> for code in range(ord("a"), ord("z") +1):
> if code == ord("m"):
> print chr(code +1)
>
> Now, this solves for the first letter after "M", but doesn't do it via a
> string
>
> thanks,


Let's think about the problem in pseudocode:

If the first letter in the string comes after m in the alphabet, print that
letter.
Otherwise, if the second letter comes after m in the alphabet, print *that*
letter.
etc. etc.

So what you want is to *iterate* through the characters that make up the
string (from start to end) until you find a character that comes after "m".

Your code above seems to *iterate* through all the characters from "a" to
"z", not the characters of a given string.

See if you can fix that first, then we'll talk about the next step.

Tony R.
aka Taser


>
> Jeffrey Dates
> www.kungfukoi.com
>
>
>
>
>
>
>   On Wed, Apr 2, 2008 at 12:44 PM, Jeffrey Dates <[EMAIL PROTECTED]>
> wrote:
>
> > Greetings,
> >
> > I have no previous experience in scripting.  Python is my first
> > language...
> > I'm currently trying to build a logic model for how to 'think' in
> > Python, so please excuse my ignorance.
> >
> > Currently, I'm running through some basic 101 tutorials, to wrap my head
> > around solving problems.
> > I'm looking for some advice on how to solve the following exercise:
> >
> > "Write a program that prints the first letter of a string that comes
> > after 'm' in the alphabet."
> >
> > I hope this is not too elementary.
> >
> > I do understand basic, basic concepts.  iteration, for loops, etc.
> > Just having trouble with syntax, and how to format my logic.
> >
> > thank you in advance for any help or examples.
> >
> > Jeffrey Dates
> > www.kungfukoi.com
> >
> >
> >
> >
> >
> >
>
> ___
> 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] info, help, guidence,...

2007-12-05 Thread taserian
Sorry if this isn't the right place for it, but today's xkcd comic strip is
very apropos for the newly illuminated in all things Python.

http://www.xkcd.com/

Tony R.

On Dec 5, 2007 12:00 PM, bhaaluu <[EMAIL PROTECTED]> wrote:

> Greetings,
>
> On Dec 5, 2007 10:30 AM, jeff witt <[EMAIL PROTECTED]> wrote:
> >
> > Hello,
> > i have some questions about programming in general and python,..
> > my brother (who is a programmer) guides me to ".net" languages,  and i
> am
> > not too sure why, however, he is getting sick of me pestering him with
> my
> > questions,..
> > i like the little i know about python, it seems to be user friendly,
> > however, i am not finding clear answers about what it does compared to
> > ".net" for example.
> >  I really know nothing about programming (which i am sure is obvious) so
> ANY
> > info would be helpful, ...
> >
> > here are a few questions that go through my head...
> >  how does python get applied to a GUI?
>
> http://wiki.python.org/moin/GuiProgramming
> TkInter is Python's "standard" GUI library
>
> > why dont universities teach it? is
> > there an online class i can take for it?  training certificates?   is it
> > accepted in the world of programming professionally?  ( i am interested
> in a
> > career too, as well as a new hobby),.
>
> Some universities do use Python to teach Computer Science topics.
> There are several online tutorials to get you started, for example:
> http://docs.python.org/tut/
> is the 'official' Python tutorial
>
> >   i use linux, and python seems to be everywhere for linux,.. and i read
> > that it works on windows too but is it accepted in "those" circles?
> > what is pythons strengths and weaknesses, IE. web/Internet, or program
> > development, operating system things,...   what would you (or you guys)
> > recomend for the first language?  or like my brother says, "just learn
> > something and stop asking me questions"
>
> Python is an excellent first programming language.
> The Tutor list is for learning Python as a first programming language.
> There seem to be an equal number of Tutors who use Linux or Windows.
>
> > if python was released in 1991 how long will it remain a current or a
> > applicable language? or i guess i am asking, what is the normal life of
> a
> > programming language before it is obsolete?
>
> That's a good question!
>
> >
> > well, like i mentioned, any help or info would be greatly appreciated,
> i
> > have been to some of the beginner sites and tried the whole "hello
> world"
> > thing, and i unfortunately realize i am years from actually contributing
> to
> > any open source project,  (especially since i am still struggling with
> the
> > file system in linux [only been using it for 8or9 months])
> >
> > God bless you  guys, and thank you for your site and willingness to
> share
> > and help!
> >
> > jeff
>
> There are several excellent tutorials and books online for free.
> You'll have to check them out and see which ones 'click' for you.
> Each person learns stuff differently, and each writer has a different
> 'style' of writing, so you might find two tutorials that cover the same
> things, but you'll like one better than the other.
>
> This is a good place to ask questions!
> Happy Programming!
> --
> b h a a l u u at g m a i l dot c o m
> http://www.geocities.com/ek.bhaaluu/python/index.html
> ___
> 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] for vs while

2007-09-28 Thread taserian
On 9/28/07, James <[EMAIL PROTECTED]> wrote:
>
> All,
>
> I have a dumb question...hopefully someone can shed some light on the
> difference between for and while in the situation below.
>
> I'm trying to iterate through a list I've created.  The list consists
> of a command, followed by a 'logging' message (a message printed to a
> console or log file after the command is run).
>
> Here's a small snippet of code:
>
># a list which includes (1) a command, and (2) something to be
> dumped into a log file after the command runs
>stuff = [ ["cat /etc/password"] , ["viewed /etc/password"] ]
>
>#works
>i = 0 ; j = 1
>while i < len( stuff ):
>os.system( str( stuff[ i ] ) )
>print stuff[ j ]
>i += 1 ; j += 1


Here you're basing yourself off of the index of the item in the list, so
stuff[0], stuff[1], etc.


The while loop does precisely what it should do: it runs the first
> command using os.system(), and then prints out the string in the
> second position of the list.
>
> Then I tried to do the same thing with a for loop that looks
> logically equivalent.  I replaced the while loop with this for loop:
>
># doesn't work
>for i in len( stuff ):
>os.system( stuff[ i ] )
>j = i + 1
>print stuff[ j ]


Here, you're using *for* in a non-Pythonic way. You mean to use i as an
iterator, but len( stuff ) is a simple integer.

You could do it this way:

   for i in range( len(stuff)):
   os.system( stuff[i] )
   j = i + 1
   print stuff[ j ]

turning the single integer into a range of integers that you can iterate
over.

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


Re: [Tutor] Finding even and odd numbers

2007-09-19 Thread taserian
>
> > The above snippet is taking advantage of a similar property of binary
> > numbers, which are base 2. What the above snippet is doing is checking
> to
> > see if that last digit is a 0 or not (asking "not n&1" is equivalent to
> > asking "n&0", since that digit can only be a 0 or 1).
>
> Not quite.  The &1 is simply checking the least significant bit in the
> word.  n&0 will always give 0.  not n&1 checks whether the last digit
> -is- or -isn't- 1.
>
> S.


Not at all, you mean. I was way off with that statement; I'll plead not
guilty by virtue of not having had enough coffee today.

<8-(  (Wearing the dunce cap. . .)

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


Re: [Tutor] Finding even and odd numbers

2007-09-19 Thread taserian
On 9/19/07, Boykie Mackay <[EMAIL PROTECTED]> wrote:

> Hi guys,
>
> I have come across a bit of code to find if a group of numbers is odd or
> even.The code snippet is shown below:
>
> if not n&1:
>return false
>
> The above should return false for all even numbers,numbers being
> represented by n.I have tried to wrap my head around the 'not n&1' but
> I'm failing to understand what's going on.Could someone please explain
> the statement.


I'll respond more from a general programming point of view than as a Python
expert (far from it!).

You can always tell if a regular number is divisible by 10, by just looking
at the last digit; if it's a zero, it is, and if it's anything else, it
isn't. That's a property of the decimal (base 10) system.

The above snippet is taking advantage of a similar property of binary
numbers, which are base 2. What the above snippet is doing is checking to
see if that last digit is a 0 or not (asking "not n&1" is equivalent to
asking "n&0", since that digit can only be a 0 or 1). Since binary numbers
are base 2, any binary number that ends in a 0 is divisible by 2, analogous
to the decimal number example above.

The technique being used to determine the value of the last digit is a
bitwise-AND. It compares the binary digits in the representation of n with
the binary digits in the representation of 1 on a one-to-one positional
arrangement. If either number has a zero in a certain position, the result
will have a zero in that position as well; if both numbers have a 1 in that
position, the result will have a 1.

As an example, I'll represent 4 as a binary number:

100 (4 in binary)
001 (1 in binary)
-
000 (Result of bitwise-AND)

and now using 5 as our input:

101 (5 in binary)
001 (1 in binary)

001 (Result of bitwise-AND)

Since 1 represented in binary is all zeroes except for the last digit, the
only way to get anything different from 000 as a result is for the last
digit to be 1.

Hopefully this didn't confuse you anymore. Experts, feel free to chime in.

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


Re: [Tutor] Bookpool sale on Addison Wesley

2007-08-09 Thread taserian
I think it's intended to be a collegiate-level textbook, and not a
find-a-copy-at-your-local-bookstore type of book. Textbooks are considerably
more expensive.

Tony R.

On 8/9/07, Sean Azelton <[EMAIL PROTECTED]> wrote:
>
> Oh - I didn't mean Bookpool was too expensive - they are almost half
> the price of Amazon on this book.  for clarification - I was wondering
> why the "Object-Oriented Programming in Python" book lists for $102.00
> US when most books list for half that price.
>
> Sean
>
> On 8/9/07, Sean Azelton <[EMAIL PROTECTED]> wrote:
> > Thanks Kent.
> >
> > Can anyone tell me why the below book is listed as S expensive?
> > With the sale Kent mentioned, it looks like a great deal - but
> > unfortunately I don't really know anything about the authors.
> >
> > Object-Oriented Programming in Python
> > Michael H Goldwasser, David Letscher
> > Prentice Hall
> > List Price: $102.00
> > Our Price: $55.95
> > You Save: $46.05 (45% Off)
> >
> > Estimated Publication Date November 2007, 700 pages, ISBN 0136150314
> >
> > Is this a good buy?
> >
> > Thanks,
> >
> > Sean Azelton
> > University of Notre Dame
> >
> > Kent Johnson wrote:
> > > Bookpool is having a sale on all books from Addison-Wesley and
> Prentice
> > > Hall. In my opinion these are two of the best publishers for top-notch
> > > computer titles.
> > >
> > > A few Python books on sale:
> > > Core Python Programming $27.25
> > > http://www.bookpool.com/sm/0132269937
> > >
> > > Rapid Web Applications with TurboGears $24.50
> > > http://www.bookpool.com/sm/0132433885
> > >
> > > Some recommended non-Python books:
> > > Design Patterns: Elements of Reusable Object-Oriented Software $32.95
> > > http://www.bookpool.com/sm/0201633612
> > >
> > > Refactoring: Improving the Design of Existing Code
> > > http://www.bookpool.com/sm/0201485672
> > >
> > > Agile Software Development Principles, Patterns, and Practices
> > > http://www.bookpool.com/sm/0135974445
> > >
> > > Extreme Programming Explained: Embrace Change, 2nd Edition
> > > http://www.bookpool.com/sm/0321278658
> > > and all the other books in this series
> > >
> > > These are just a few personal favorites, there are many more excellent
> > > books on sale.
> > >
> > > Kent
> > > ___
> > > 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


Re: [Tutor] How to improve

2007-07-16 Thread taserian

Thank you both, Alan and Gregor. Sorry I didn't reply earlier; just a bit
overwhelmed with a family situation over here.

Alan, looks like I'll have to go over list comprehension as a way to
initialize variables. I recall when I first started programming this, I
tried wordlist = [] * 31, completely overlooking the fact that all of the
list were in fact the same, and when debugging finding that my wordlist had
been copied 31 times!

Gregor, I like your version since you don't have to constrain the list
artificially, as I did. For this problem in particular, the longest
interlaced word I could find was 11 characters long, and the longer you go,
the less probable it is that you'll find one. 31 seemed like a good enough
value, but I'll probably change my version to look like yours.

Thanks again, guys!

Tony R.

On 7/12/07, Gregor Lingl <[EMAIL PROTECTED]> wrote:


taserian schrieb:
> I've been programming for years before encountering Pythoin, but in
> much more verbose languages, and I appreciate the fact that Python is
> so terse and still accomplishes so much. Still, I have difficulty
> thinking in Python, and tend to revert to longer programs for what
> seems to be simple tasks. Sometimes it's because I'm just not aware of
> a library function, but many times it's because there's just some
> elegant way to solve my kludge.
>
> As an exercise in Python, I decided to solve a toy problem called
> "interleave". The idea is that I want to determine how many words in
> the English language are decomposable into two words by taking it
> apart one letter at a time. So the word "theorems" could be decomposed
> into "term" and "hoes" (original word = abababab, decomposed words =
>  and , with all letters in the same order as in the original
> word).
>
> I'd like to see how I could improve the program below for this, and
> make it more Python-ish.
>
Hi taserian,

I've just produced an alternative solution of your problem
(based on your ideas). The main difference is, that I use
a wordlength-dictionary. This version has the advantage, that
it doesn't make an assumption about the max word length.
I don't consider it to be an improvement, just an example
that uses different language elements of Python in some places.
Hope you enjoy it.

 START

wordlengthdict = {}

for word in open("wordlist.txt").read().split():
wordlengthdict.setdefault(len(word),[]).append(word)

outfile = open('InterleaveEnglishYAWL.txt', 'w')

for l in sorted(wordlengthdict.keys()):
print l
for w in wordlengthdict[l]:
wordtriple = (w1, w2, dummy)  = w[0::2], w[1::2], w
if  w1 in wordlengthdict.get(len(w1),[]) and w2 in
wordlengthdict.get(len(w2),[]):
outfile.write("(%s, %s, %s)\n" % wordtriple)
print wordtriple

outfile.close();

 END

Best regards,
Gregor

> = = = = START
>
> def decompose(longword):
> word1 = longword[0::2]
> word2 = longword[1::2]
> return (word1, word2)
>
> wordlengthlist = [None] * 31
> for i in range(0,len(wordlengthlist)):
> wordlengthlist[i] = []
> results = []
>
> for lineread in open("word.list"):
> for word in lineread.split():
> if len(word)<31:
> wordlengthlist[len(word)].append(word)
>
> outfile = open('InterleaveEnglishYAWL.txt', 'w')
>
> for x in range(4, 31):
> print x
> for i in wordlengthlist[x]:
> twowords = decompose(i)
> word1 = twowords[0]
> word2 = twowords[1]
> if word1 in wordlengthlist[len(word1)] and word2 in
> wordlengthlist[len(word2)]:
> outfile.write("(" + word1 + ", " + word2 + ", " + i + ")\n")
> print (word1, word2, i)
>
> outfile.close();
>
> = = = = END
>
> Tony R.
>
> 
>
> ___
> 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] How to improve

2007-07-12 Thread taserian

I've been programming for years before encountering Pythoin, but in much
more verbose languages, and I appreciate the fact that Python is so terse
and still accomplishes so much. Still, I have difficulty thinking in Python,
and tend to revert to longer programs for what seems to be simple tasks.
Sometimes it's because I'm just not aware of a library function, but many
times it's because there's just some elegant way to solve my kludge.

As an exercise in Python, I decided to solve a toy problem called
"interleave". The idea is that I want to determine how many words in the
English language are decomposable into two words by taking it apart one
letter at a time. So the word "theorems" could be decomposed into "term" and
"hoes" (original word = abababab, decomposed words =  and , with all
letters in the same order as in the original word).

I'd like to see how I could improve the program below for this, and make it
more Python-ish.

= = = = START

def decompose(longword):
   word1 = longword[0::2]
   word2 = longword[1::2]
   return (word1, word2)

wordlengthlist = [None] * 31
for i in range(0,len(wordlengthlist)):
   wordlengthlist[i] = []
results = []

for lineread in open("word.list"):
   for word in lineread.split():
   if len(word)<31:
   wordlengthlist[len(word)].append(word)

outfile = open('InterleaveEnglishYAWL.txt', 'w')

for x in range(4, 31):
   print x
   for i in wordlengthlist[x]:
   twowords = decompose(i)
   word1 = twowords[0]
   word2 = twowords[1]
   if word1 in wordlengthlist[len(word1)] and word2 in
wordlengthlist[len(word2)]:
   outfile.write("(" + word1 + ", " + word2 + ", " + i + ")\n")
   print (word1, word2, i)

outfile.close();

= = = = END

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


[Tutor] Trouble creating DB2 drivers

2007-02-26 Thread taserian

I'm trying to build the DB2 drivers I downloaded from
http://sourceforge.net/projects/pydb2
but I'm getting an error message when I try installing them (after doing
"python setup.py install"):

Your DB2 root is: C:\Program Files\SQLLIB\
WARNING: it seems that you did not install 'Application Development Kit'.
Compilation may fail.

running install
running build
running build_py
running build_ext
building '_db2' extension
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\cl.exe /c /nologo
/Ox
/MD /W3 /GX /DNDEBUG "-IC:\Program Files\SQLLIB\include"
-IC:\Python25\include
-IC:\Python25\PC /Tc_db2_module.c /Fobuild\temp.win32-
2.5\Release\_db2_module.obj
_db2_module.c
_db2_module.c(24) : fatal error C1083: Cannot open include file: 'sqlcli1.h':
No such file or directory
error: command '"C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\bin\cl.exe"' failed with exit status 2


- - - -

I can't seem to find anything through Google about the "Application
Development Kit" that the error mentions. Can anyone help?

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