Re: [Tutor] if statement help

2015-03-29 Thread Danny Yoo
On Thu, Mar 26, 2015 at 5:42 PM, Priya Persaud  wrote:
> Hello,
>
> I recently learned about if statements and math functions. For my class we
> are unit testing absolute values and have to make if statements so the
> tests pass, but we cannot use built in functions like (abs). How do I start
> it, I am so lost.
>
> Thank you


There are multiple situations where we need to teach the computer to
compute a function, where it doesn't know about the function already.
Your teacher appears to be trying to teach you how to build basic
functions, which is admirable.


Pretend that you're talking to someone who doesn't know what the
absolute value function does.

  * Can you say what the absolute value function does?  What's its purpose?

  * Can you give a few examples of inputs and expected outputs of the function?


By the way, if you have some free time, you might find the following
book helpful: http://www.ccs.neu.edu/home/matthias/HtDP2e/  It's not
Python, but it tries to teach how to tackle the kind of programming
problems you'll see in a beginner's class.  What's good about it is
that it concentrates on methodology and problem-solving strategies,
all to keep yourself from getting lost.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] if statement help

2015-03-29 Thread Priya Persaud
Hello,

I recently learned about if statements and math functions. For my class we
are unit testing absolute values and have to make if statements so the
tests pass, but we cannot use built in functions like (abs). How do I start
it, I am so lost.

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


Re: [Tutor] If statement The Python Tutorial 3.4.1

2014-09-14 Thread Alan Gauld

On 14/09/14 09:00, ALAN GAULD wrote:


So, to IDLE, your code looks like

if x < 0:
   print(...)
elif x == 0:


Web mail screwed things up. That should be:

> if x < 0:
>print(...)
> elif x == 0:


To fix it you need to make it look like this on screen:



if x < 0:

 print(...)
elif x == 0:
 print()
else:
 print()


Which looks wrong to you and me but IDLE sees it as good.



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

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


Re: [Tutor] If statement The Python Tutorial 3.4.1

2014-09-14 Thread ALAN GAULD
OK, You are using IDLE and have discovered one of its "features" 
which I consider a bug...

The alignment of code breaks in IDLE when there is no >>> in the line. 
You need to ignore the >>> characters.

So, to IDLE, your code looks like

if x < 0:
           print(...)
      elif x == 0:

because IDLE doesn't see the >>>.


So it gives you the unindent error because it thinks elif is not aligned 
with if, even though it looks that way to you...

To fix it you need to make it look like this on screen:

>>> if x < 0:
            print(...)
elif x == 0:
      print()
else:
      print()

Which looks wrong to you and me but IDLE sees it as good.

And this is one of the rare cases where posting an image rather 
than a cut n' paste of the code is actually useful, because it 
shows that you are using IDLE...

HTH
Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/

http://www.flickr.com/photos/alangauldphotos



>
> From: Gregory Donaldson 
>To: Alan Gauld  
>Sent: Sunday, 14 September 2014, 4:28
>Subject: Re: [Tutor] If statement The Python Tutorial 3.4.1
> 
>
>
>
>​
>
>
>
>On Sat, Sep 6, 2014 at 7:49 PM, Alan Gauld  wrote:
>
>On 06/09/14 00:29, Gregory Donaldson wrote:
>>
>>
>>This is what it looks like when I try to get it to work.
>>>
>>>
>>>x = int(input("Please enter an integer: "))
>>>>>>
>>>Please enter an integer: 42
>>>
>>>
>>>if x < 0:
>>>>>>
>>>x = 0
>>>
>>>print('Negative changed to zero')
>>>
>> I'm guessing that you actually indented the two lines
>>above but not the one below - otherwise you'd get an
>>indentation error by now, not a syntax error below.
>>
>>
>>elif x == 0:
>>>
>>>SyntaxError: invalid syntax
>>>
>> Are you sure this is where you get the syntax error?
>>Or did you maybe hit enter too many times thus ending
>>the if block?
>>
>>
>>It needs to follow this pattern:
>>
>>if x < 0:
>>   x = 0
>>   print('Negative changed to zero')
>>elif x == 0:
>>    print('you typed zero')
>>else:
>>   print('alls well')
>>
>>So the if/elif and else lines are all lined up with each
>>other and the indented lines are likewise lined up.
>>And if working in the interactive prompt you must not
>>have blank lines (Note: You can have blanks when creating
>>a program file)
>>
>>Indentation is always important in programming for readability,
>>but in Python its vital for Python to understand your code
>>correctly.
>>
>>HTH
>>-- 
>>Alan G
>>Author of the Learn to Program web site
>>http://www.alan-g.me.uk/
>>http://www.flickr.com/photos/alangauldphotos
>>
>>
>>___
>>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


Re: [Tutor] If statement The Python Tutorial 3.4.1

2014-09-06 Thread Alan Gauld

On 06/09/14 00:29, Gregory Donaldson wrote:


This is what it looks like when I try to get it to work.


x = int(input("Please enter an integer: "))


Please enter an integer: 42


if x < 0:


x = 0

print('Negative changed to zero')


I'm guessing that you actually indented the two lines
above but not the one below - otherwise you'd get an
indentation error by now, not a syntax error below.


elif x == 0:

SyntaxError: invalid syntax


Are you sure this is where you get the syntax error?
Or did you maybe hit enter too many times thus ending
the if block?


It needs to follow this pattern:

if x < 0:
   x = 0
   print('Negative changed to zero')
elif x == 0:
   print('you typed zero')
else:
   print('alls well')

So the if/elif and else lines are all lined up with each
other and the indented lines are likewise lined up.
And if working in the interactive prompt you must not
have blank lines (Note: You can have blanks when creating
a program file)

Indentation is always important in programming for readability,
but in Python its vital for Python to understand your code
correctly.

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

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


Re: [Tutor] If statement The Python Tutorial 3.4.1

2014-09-06 Thread Joel Goldstick
On Fri, Sep 5, 2014 at 7:29 PM, Gregory Donaldson  wrote:
> I've tried to copy this example from the Tutorial into the Python Idle, but
> it doesn't seem to recognize it.
>
> 4.1. if Statements¶
>
> Perhaps the most well-known statement type is the if statement. For example:
>

>
 x = int(input("Please enter an integer: "))
> Please enter an integer: 42
 if x < 0:
> ... x = 0
> ... print('Negative changed to zero')
> ... elif x == 0:
> ... print('Zero')
> ... elif x == 1:
> ... print('Single')
> ... else:
> ... print('More')
> ...
> More
>
> This is what it looks like when I try to get it to work.
>
 x = int(input("Please enter an integer: "))
>
> Please enter an integer: 42
>
 if x < 0:
>
> x = 0
>
> print('Negative changed to zero')
>
you need to indent the above two statements.  Use 4 spaces

> elif x == 0:
>
> SyntaxError: invalid syntax
>
 if x < 0:
>
> x = 0
>
> print('Negative changed to zero')
>
> elif x == 0:
>
>
>
also, please set your mail to send text

In python, indentation matters
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



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


[Tutor] If statement The Python Tutorial 3.4.1

2014-09-06 Thread Gregory Donaldson
I've tried to copy this example from the Tutorial into the Python Idle, but
it doesn't seem to recognize it.

4.1. if 
 Statements¶


Perhaps the most well-known statement type is the if
 statement. For
example:
>>>

>>> x = int(input("Please enter an integer: "))Please enter an integer: 42>>> 
>>> if x < 0:... x = 0... print('Negative changed to zero')... elif x 
>>> == 0:... print('Zero')... elif x == 1:... print('Single')... 
>>> else:... print('More')...More

This is what it looks like when I try to get it to work.

>>> x = int(input("Please enter an integer: "))

Please enter an integer: 42

>>> if x < 0:

x = 0

print('Negative changed to zero')

elif x == 0:

SyntaxError: invalid syntax

>>> if x < 0:

x = 0

print('Negative changed to zero')

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


Re: [Tutor] if statement problems(noob question)

2013-04-08 Thread Dave Angel

On 04/08/2013 07:55 AM, Steven D'Aprano wrote:

On 08/04/13 20:45, Dave Angel wrote:


will always fail, since the integer 2 is not equal to the type int.
In Python 2.x, when you compare objects of different types, you
generally get unequal.  (Exception, if you define your own classes,
you can define how they compare to others)  In Python 3, you'd get an
exception.



Not so. Equality testing is always allowed.



Right.  Thanks for the correction.  I should know better by now.

I knew I should have left that part off, since the OP is using version 2 
anyway.


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


Re: [Tutor] if statement problems(noob question)

2013-04-08 Thread Steven D'Aprano

On 08/04/13 20:21, Max Smith wrote:

Hi, everyone whom might read this, im Max and i am really new to coding,
been going at it for about two weeks using codeacademy and the book "think
python".
when i decided to experiment a little with if statements i ran into the
following problem:

def plus(x,y):
 if x and y == int or float:
 print "The answer is: " + str(x+y)
 else:
 print "not a number"



Your problem here is that you've let Python's friendly syntax fool you into
thinking you can program in English. Python's good, but it's not that good!


In English, I might say to you:

"If x and y are ints, or floats, then do this ..."

which you've translated into Python as:

if x and y == int or float: ...


But that's not what it means to Python. What Python does is quite different.
Translating the above:

if x is a truthy value,
   and y equals the function "int",
   or the function "float" is a truthy value,
then ...


What do I mean by "is a truthy value"?

Python has a rule that *every* value, numbers, strings, lists, etc, everything,
can be considered "true-like" or "false-like". The rules are:

- values which are considered "empty" or "nothing" in some sense are treated
  as false-like:

  zero numbers: 0, 0.0
  empty string: ''
  empty containers (lists, dicts, tuples)
  None
  False

  are all "false-like" or "falsey" values.


- values which are considered non-empty, or "something", are treated as
  true-like:

  every number except zero, e.g. 0.0001, 42, -17.4
  every non-empty string, e.g. "hello world"
  every non-empty container, e.g. [1, 2, 3]
  True
  functions
  modules
  etc.

  are all "true-like" or "truthy" values.


So let's go back to your code:

if x and y == int or float: ...


1) First, Python checks whether x is a truthy value. In the examples you give,
it is, so the if-clause starts to look like this:

if True and y == int or float: ...


2) Next, Python checks whether y equals the int function. In this case, it does
not, so the if-clause looks like this:

if True and False or float: ...

and Python can simplify "True and False" to just False:

if False or float: ...


3) Next, Python checks whether the float function is a truthy value. Since
functions are "something" rather than "nothing", it is considered truthy, and
the if-clause looks like this:

if False or True: ...

which Python simplifies to:

if True: ...


and so the if-clause *always* evaluates as True.



So what do you have to write instead?

Firstly, you can't check the type of a value with equals. You use the isinstance
function instead. To check if x is an int:

if isinstance(x, int): ...


To check if x is an int, or a float, make the second argument a tuple of types:


if isinstance(x, (int, float)): ...


To check is x *and* y are ints, or floats, you have to check each one 
separately:


number = (int, float)  # tuple of two types
if isinstance(x, number) and isinstance(y, number): ...




Try that, and see how your code works.





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


Re: [Tutor] if statement problems(noob question)

2013-04-08 Thread Steven D'Aprano

On 08/04/13 20:45, Dave Angel wrote:


will always fail, since the integer 2 is not equal to the type int.  In Python 
2.x, when you compare objects of different types, you generally get unequal.  
(Exception, if you define your own classes, you can define how they compare to 
others)  In Python 3, you'd get an exception.



Not so. Equality testing is always allowed.

In Python 3:


py> 25 == "hello world"
False


exactly the same as in Python 2. It's only ordering comparisons, < <= >= > that 
raise an error with incompatible types:

py> 25 <= "hello world"
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unorderable types: int() <= str()



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


Re: [Tutor] if statement problems(noob question)

2013-04-08 Thread Dave Angel

On 04/08/2013 06:37 AM, Woody 544 wrote:

Max,

You've made the arguments a string (so never a number) in:

print "The answer is: " + str(x+y)

MJ


That has nothing to do with the issue.  The str() function call is 
unnecessary, but harmless.  If the two values x and y are ints or 
floats, they will get added in the obvious way long before being 
converted to str().


If they are already strings, they'll be concatenated long before str() 
does a null conversion on the resultant string.


The problem, as I stated in my own response, is that the if statement 
does nothing useful for checking of types.



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


Re: [Tutor] if statement problems(noob question)

2013-04-08 Thread Dave Angel

On 04/08/2013 06:21 AM, Max Smith wrote:

Hi, everyone whom might read this, im Max and i am really new to coding,
been going at it for about two weeks using codeacademy and the book "think
python".
when i decided to experiment a little with if statements i ran into the
following problem:

def plus(x,y):
 if x and y == int or float:


What is it you expect this to do?  Have you tried a similar, simpler 
expression to get acquainted?

x = 2
if x == int:

will always fail, since the integer 2 is not equal to the type int.  In 
Python 2.x, when you compare objects of different types, you generally 
get unequal.  (Exception, if you define your own classes, you can define 
how they compare to others)  In Python 3, you'd get an exception.


The way you should test an object to see if it's an instance of a class 
is to use isinstance()

   http://docs.python.org/2/library/functions.html#isinstance

isinstance(x, int)
And if you need to test more than one type or class, use a tuple of the 
types:


isinstance(x, (int, float))

Now you can combine more than one such test:

if  isinstance(x, (int, float)) and isinstance(y, (int, float)):



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


Re: [Tutor] if statement problems(noob question)

2013-04-08 Thread Woody 544
Max,

You've made the arguments a string (so never a number) in:

print "The answer is: " + str(x+y)

MJ
On Apr 8, 2013 6:23 AM, "Max Smith"  wrote:

> Hi, everyone whom might read this, im Max and i am really new to coding,
> been going at it for about two weeks using codeacademy and the book "think
> python".
> when i decided to experiment a little with if statements i ran into the
> following problem:
>
> def plus(x,y):
> if x and y == int or float:
> print "The answer is: " + str(x+y)
>
> else:
> print "not a number"
>
>
> plus(2,2)
> plus("one","two")
>
> concatenates one and two insted of printing "not a number"
>
> i have tried to simplify by not cheacking for float values an i have also
> tried.
>
> def plus(x,y):
> if x and y == int or float:
> print "The answer is: " + str(x+y)
>
> elif x or y != int or float:
> print "not a number"
>
> Am i perhaps missing something with the logic gates?
>
> Any help is greatly appreciated !
>
> ___
> 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] if statement problems(noob question)

2013-04-08 Thread Max Smith
Hi, everyone whom might read this, im Max and i am really new to coding,
been going at it for about two weeks using codeacademy and the book "think
python".
when i decided to experiment a little with if statements i ran into the
following problem:

def plus(x,y):
if x and y == int or float:
print "The answer is: " + str(x+y)

else:
print "not a number"


plus(2,2)
plus("one","two")

concatenates one and two insted of printing "not a number"

i have tried to simplify by not cheacking for float values an i have also
tried.

def plus(x,y):
if x and y == int or float:
print "The answer is: " + str(x+y)

elif x or y != int or float:
print "not a number"

Am i perhaps missing something with the logic gates?

Any help is greatly appreciated !
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] If statement optimization

2011-09-16 Thread bodsda
Thanks for the explanation - very clear.

Cheers,
Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: Steven D'Aprano 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Fri, 16 Sep 2011 20:43:45 
To: Tutor - python List
Subject: Re: [Tutor] If statement optimization

bod...@googlemail.com wrote:
> Hi,
> 
> In a normal if,elif,elif,...,else statement, are the conditions checked in a 
> linear fashion?

Yes.


> I am wondering if I should be making an effort to put the most likely true 
> condition at the beginning of the block

Probably not. The amount of time used in the average if...elif is 
unlikely to be significant itself. Don't waste your time trying to 
optimize something like this:


if n < 0:
...
elif n == 0:
...
else:
...


However, there are exceptions.

If the tests are very expensive, then it might be worthwhile putting the 
most likely case first. Or at least, put the cheapest cases first, leave 
the expensive ones for last:

if sum(mylist[1:]) > 1000 and mylist.count(42) == 3 and min(mylist) < 0:
 ...
elif len(mylist) < 5:
 ...

I probably should swap the order there, get the cheap len() test out of 
the way, and only perform the expensive test if that fails.


If you have LOTS of elif cases, like *dozens*, then firstly you should 
think very hard about re-writing your code, because that's pretty poor 
design... but if you can't change the design, then maybe it is 
worthwhile to rearrange the cases.

If you have something like this:


if s == "spam":
 func_spam(x)
elif s == "ham":
 func_ham(x)
elif s == "cheese":
 func_cheese(x)


you can often turn this into a dispatch table:


table = {"spam": func_spam, "ham": func_ham, "cheese": func_cheese}
func = table[s]  # lookup in the dispatch table
func(x)  # finally call the function


Note that inside table, you don't call the functions.

This pattern is especially useful, as lookup in a table in this manner 
takes close enough to constant time, whether there is one item or a million.



-- 
Steven

___
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] If statement optimization

2011-09-16 Thread Steven D'Aprano

bod...@googlemail.com wrote:

Hi,

In a normal if,elif,elif,...,else statement, are the conditions checked in a 
linear fashion?


Yes.



I am wondering if I should be making an effort to put the most likely true 
condition at the beginning of the block


Probably not. The amount of time used in the average if...elif is 
unlikely to be significant itself. Don't waste your time trying to 
optimize something like this:



if n < 0:
   ...
elif n == 0:
   ...
else:
   ...


However, there are exceptions.

If the tests are very expensive, then it might be worthwhile putting the 
most likely case first. Or at least, put the cheapest cases first, leave 
the expensive ones for last:


if sum(mylist[1:]) > 1000 and mylist.count(42) == 3 and min(mylist) < 0:
...
elif len(mylist) < 5:
...

I probably should swap the order there, get the cheap len() test out of 
the way, and only perform the expensive test if that fails.



If you have LOTS of elif cases, like *dozens*, then firstly you should 
think very hard about re-writing your code, because that's pretty poor 
design... but if you can't change the design, then maybe it is 
worthwhile to rearrange the cases.


If you have something like this:


if s == "spam":
func_spam(x)
elif s == "ham":
func_ham(x)
elif s == "cheese":
func_cheese(x)


you can often turn this into a dispatch table:


table = {"spam": func_spam, "ham": func_ham, "cheese": func_cheese}
func = table[s]  # lookup in the dispatch table
func(x)  # finally call the function


Note that inside table, you don't call the functions.

This pattern is especially useful, as lookup in a table in this manner 
takes close enough to constant time, whether there is one item or a million.




--
Steven

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


[Tutor] If statement optimization

2011-09-16 Thread bodsda
Hi,

In a normal if,elif,elif,...,else statement, are the conditions checked in a 
linear fashion?

I am wondering if I should be making an effort to put the most likely true 
condition at the beginning of the block

Thanks,
Bodsda 
Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if statement

2011-06-10 Thread Jeremy G Clark
Sorry, jumping in on this thread a couple days late...

Steven's suggestion is how I figured out a similar problem recently.  If you're 
executing the code through a windows command line, you might be getting the 
carriage-return character returned to the program (this behavior doesn't happen 
in IDLE).  Remove it by using rstrip like so:

password = input("Enter your password: ").rstrip('\r')

Jeremy

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


Re: [Tutor] if statement

2011-06-08 Thread Steven D'Aprano

Matthew Brunt wrote:

i'm very new to python (currently going through a python for beginners
book at work to pass the time), and i'm having trouble with an if
statement exercise.  basically, i'm creating a very simple password
program that displays "Access Granted" if the if statement is true.
the problem i'm having is that no matter what i set the password to,
it seems like it's ignoring the if statement (and failing to print
"Access Granted").  the code is copied below.  i'm pretty sure it's my
own programming ignorance, but i would greatly appreciate any
feedback.


More important than the exact solution to the problem is to learn how to 
solve this sort of problem:




password = input("Enter your password: ")
if password == "a":
   print("Access Granted")


If this is not doing what you expect, you should see what password 
actually is:


print(password)

It might also help to print the repr() of password, in case there are 
any unexpected spaces or other characters:


print(repr(password))

Of course, if you're getting an error instead, then you should read the 
error message, and look at the full traceback, and see what it says.




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


Re: [Tutor] if statement

2011-06-07 Thread Alan Gauld


"Andre Engels"  wrote 


Actually, no, this case it's not your ignorance. What is probably
going on is that you are using Python 2, but the book is going with
Python 3. 


You can quickly check the version by just typing python at 
an OS command prompt to get into the interactive interpreter(>>>).


The welcome message should tell you the version you 
are running.


HTH,

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


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


Re: [Tutor] if statement

2011-06-07 Thread Andre Engels
On Tue, Jun 7, 2011 at 11:26 PM, Matthew Brunt  wrote:
> i'm very new to python (currently going through a python for beginners
> book at work to pass the time), and i'm having trouble with an if
> statement exercise.  basically, i'm creating a very simple password
> program that displays "Access Granted" if the if statement is true.
> the problem i'm having is that no matter what i set the password to,
> it seems like it's ignoring the if statement (and failing to print
> "Access Granted").  the code is copied below.  i'm pretty sure it's my
> own programming ignorance, but i would greatly appreciate any
> feedback.

Actually, no, this case it's not your ignorance. What is probably
going on is that you are using Python 2, but the book is going with
Python 3. I won't get into the details, but the function that does
what input() does in Python 3, is called raw_input() in Python 2 (and
the Python 2 input() function is advised against using for security
reasons). Probably if you change input to raw_input in your program,
it does do what you want it to do.

> # Granted or Denied
> # Demonstrates an else clause
>
> print("Welcome to System Security Inc.")
> print("-- where security is our middle name\n")
>
> password = input("Enter your password: ")
>
> if password == "a":
>   print("Access Granted")
>
> input("\n\nPress the enter key to exit.")
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] if statement

2011-06-07 Thread Matthew Brunt
i'm very new to python (currently going through a python for beginners
book at work to pass the time), and i'm having trouble with an if
statement exercise.  basically, i'm creating a very simple password
program that displays "Access Granted" if the if statement is true.
the problem i'm having is that no matter what i set the password to,
it seems like it's ignoring the if statement (and failing to print
"Access Granted").  the code is copied below.  i'm pretty sure it's my
own programming ignorance, but i would greatly appreciate any
feedback.

# Granted or Denied
# Demonstrates an else clause

print("Welcome to System Security Inc.")
print("-- where security is our middle name\n")

password = input("Enter your password: ")

if password == "a":
   print("Access Granted")

input("\n\nPress the enter key to exit.")
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if statement

2010-11-04 Thread Francesco Loffredo

On 02/11/2010 20.07, Glen Clark wrote:

sorry:

NumItems = int(input("How many Items: "))


Entries = []
for In in range(0,NumItems):
Entries.append("")



for In in range(0,NumItems):
Entries[In]=str(input("Enter name " + str(In+1) + ": "))


for In in range(0,NumItems):
print(Entries[In])

confirmed = int(input("Are you happy with this? (y/n): ")

if confirmed == "y":
for In in range(0,NumItems):
   print(Entries[In] + ": " + str(In))
change = int(input("Which item would you like to change: ")
Entries[change]=str(input("Please enter a nem name: ")
else:
 #do nothing

print(Entries)


On 11/2/10, Glen Clark  wrote:

  File "/home/glen/workspace/test.py", line 19
 if confirmed == "y":
^
SyntaxError: invalid syntax


It seems to me that when you wrote the request for confirmation you just 
copied and pasted part of the first line, changing the variable name to 
'confirmed'. But you were expecting a string, so you should delete the 
leading "int(" part of that statement, what you forgot to do:


confirmed = input("Are you happy with this? (y/n): ")

So the problem was not in the missing ending parenthesis, but in those 
four characters in excess. A very similar mistake is in the request for 
a new name for Entries[change]: remember that input() ALWAYS returns a 
string.


Entries[change]=input("Please enter a new name: ")

Finally, as others have pointed out, you should put a pass statement 
after the else clause, or delete it altogether:

> if confirmed == "y":
> for In in range(0,NumItems):
>print(Entries[In] + ": " + str(In))
> change = input("Which item would you like to change: ")
> Entries[change]=input("Please enter a nem name: ")
#the following two lines may be safely deleted, or must be BOTH there
> else:
>  pass

Hope that helps,
Francesco
Nessun virus nel messaggio in uscita.
Controllato da AVG - www.avg.com
Versione: 9.0.864 / Database dei virus: 271.1.1/3235 -  Data di rilascio: 
11/03/10 09:36:00
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if statement

2010-11-02 Thread Alan Gauld


"Glen Clark"  wrote 


On a side note.. I didn't know you could do something like this:

x = z if 


Yes it's python's equivalent to the C style 


foo = testVal() ? bar : baz

Also found in other languages (Java, Javascript, Perl?)

Alan G.

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


Re: [Tutor] if statement

2010-11-02 Thread Robert Berman


> -Original Message-
> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Glen Clark
> Sent: Tuesday, November 02, 2010 3:07 PM
> To: python mail list
> Subject: Re: [Tutor] if statement
> 
> sorry:
> 
> 
> confirmed = int(input("Are you happy with this? (y/n): ")
> 
> if confirmed == "y":
>for In in range(0,NumItems):
>   print(Entries[In] + ": " + str(In))
>change = int(input("Which item would you like to change: ")
>Entries[change]=str(input("Please enter a nem name: ")
> else:
> #do nothing

Whoops. Why are you trying to make the variable "confirmed" an integer rather
than a simple 'y/n' as you are asking for?

Robert Berman





--
I am using the free version of SPAMfighter.
We are a community of 7 million users fighting spam.
SPAMfighter has removed 34 of my spam emails to date.
Get the free SPAMfighter here: http://www.spamfighter.com/len

The Professional version does not have this message


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


Re: [Tutor] if statement

2010-11-02 Thread bob gailer

On 11/2/2010 3:07 PM, Glen Clark wrote:

sorry:

NumItems = int(input("How many Items: "))


Entries = []
for In in range(0,NumItems):
Entries.append("")



for In in range(0,NumItems):
Entries[In]=str(input("Enter name " + str(In+1) + ": "))


for In in range(0,NumItems):
print(Entries[In])

confirmed = int(input("Are you happy with this? (y/n): ")

In addition to the other help - do not use int here. You will get a run 
time error when it tries to convert y or n to an integer. If that 
succeeded e.g. the user entered 3), then confirmed (an integer) will 
NEVER be == "y" (a string).

if confirmed == "y":
for In in range(0,NumItems):
   print(Entries[In] + ": " + str(In))
change = int(input("Which item would you like to change: ")
Entries[change]=str(input("Please enter a nem name: ")
else:
 #do nothing

print(Entries)

On Tue, 2010-11-02 at 15:05 -0400, Alex Hall wrote:

On 11/2/10, Glen Clark  wrote:

  File "/home/glen/workspace/test.py", line 19
 if confirmed == "y":
^
SyntaxError: invalid syntax

Why does this not work??? PyDev says "Expected:else"

It may help to see the rest of the file, or at least more of the code
surrounding this statement.

___
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




--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] if statement

2010-11-02 Thread Adam Bark

On 02/11/10 19:36, christopher.h...@allisontransmission.com wrote:



Glen Clark wrote on 11/02/2010 03:07:18 PM:

in general you should use raw_input instead of input.


> confirmed = int(input("Are you happy with this? (y/n): ")
>

It would appear that Glen is using python 3.x as he used the print 
function so input is correct.


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


Re: [Tutor] if statement

2010-11-02 Thread Alan Gauld


"Glen Clark"  wrote


confirmed = int(input("Are you happy with this? (y/n): ")

if confirmed == "y":


count the parens.

It thinks you are trying to do:

confimed = int(input('') if foo else bar)

HTH,


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


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


Re: [Tutor] if statement

2010-11-02 Thread Emile van Sebille

On 11/2/2010 12:07 PM Glen Clark said...

sorry:

NumItems = int(input("How many Items: "))


Entries = []
for In in range(0,NumItems):
Entries.append("")



for In in range(0,NumItems):
Entries[In]=str(input("Enter name " + str(In+1) + ": "))


for In in range(0,NumItems):
print(Entries[In])

confirmed = int(input("Are you happy with this? (y/n): ")


The line above (which would appear to set confirmed to an int) doesn't 
have matching parens, which causes an error to be trapped elsewhere.


Emile

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


Re: [Tutor] if statement

2010-11-02 Thread Joel Goldstick
On Tue, Nov 2, 2010 at 3:34 PM, Adam Bark  wrote:

> On 02/11/10 19:07, Glen Clark wrote:
>
>> sorry:
>>
>> NumItems = int(input("How many Items: "))
>>
>>
>> Entries = []
>> for In in range(0,NumItems):
>>Entries.append("")
>>
>>
>>
>> for In in range(0,NumItems):
>>Entries[In]=str(input("Enter name " + str(In+1) + ": "))
>>
>>
>> for In in range(0,NumItems):
>>print(Entries[In])
>>
>> confirmed = int(input("Are you happy with this? (y/n): ")
>>
>> if confirmed == "y":
>>for In in range(0,NumItems):
>>   print(Entries[In] + ": " + str(In))
>>change = int(input("Which item would you like to change: ")
>>Entries[change]=str(input("Please enter a nem name: ")
>> else:
>> #do nothing
>>
>> print(Entries)
>>
>>
>>
> Ok that's easier, you're missing a closing bracket at the end of the
>
>
> confirmed = int(input("Are you happy with this? (y/n): ")
>
> line.
> I think you might need at least a pass after else as well, although it
> should be fine to leave it out altogether once you've added the ')'.
>
> HTH,
> Adam.
>
> ___
>
if confirmed == "y":
   for In in range(0,NumItems):
  print(Entries[In] + ": " + str(In))
   change = int(input("Which item would you like to change: ")
   Entries[change]=str(input("Please enter a nem name: ")

> else:
> #do nothing
>
Actually, I caught two mismatched parens.  In the line starting with
'change' and the following line.

Fix those first


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



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


Re: [Tutor] if statement

2010-11-02 Thread christopher . henk
Glen Clark wrote on 11/02/2010 03:07:18 PM:

in general you should use raw_input instead of input.


> confirmed = int(input("Are you happy with this? (y/n): ")
> 

you are missing a closing parenthesis above, and converting a string (y,n) 
to and int
> if confirmed == "y":

you are comparing an int and a string here, probably not what you want 
(see above).

>for In in range(0,NumItems):
>   print(Entries[In] + ": " + str(In))
>change = int(input("Which item would you like to change: ") 

again, you are missing a closing parenthesis above

>Entries[change]=str(input("Please enter a nem name: ")

again, you are missing a closing parenthesis above

> else:
> #do nothing

you need to put pass here, you can't just have a comment in a block
> 
> print(Entries)
> 


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


Re: [Tutor] if statement

2010-11-02 Thread Glen Clark
Okay, 

Thank you very much for the help guys :)

On a side note.. I didn't know you could do something like this:

x = z if 

(thus why I needed the closing parenthesis)

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


Re: [Tutor] if statement

2010-11-02 Thread Joel Goldstick
On Tue, Nov 2, 2010 at 3:17 PM, Glen Clark  wrote:

> I tried that and it still does not work.
>
> On Tue, 2010-11-02 at 15:13 -0400, James Reynolds wrote:
> > the syntax is:
> >
> >
> > if True:
> >  do something that you want to do if the condition you are testing
> > is True, in your case when confirmed is "y"
> > elif True:
> >  optional: do something else when the above condition is false and
> > this condition is True.
> > else:
> >  do something else when the above conditions are false.
> >
> >
> > You can try this,
> >
> >
> > if confirmed == "y":
> > stuff
> > else:
> > pass
> >
> >
> >
> >
> > On Tue, Nov 2, 2010 at 3:02 PM, Glen Clark  wrote:
> >  File "/home/glen/workspace/test.py", line 19
> >if confirmed == "y":
> >   ^
> > SyntaxError: invalid syntax
> >
> > Why does this not work??? PyDev says "Expected:else"
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
>   change = int(input("Which item would you like to change: ")

In the line about you have mismatched parentheses.  This confuses the parser

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



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


Re: [Tutor] if statement

2010-11-02 Thread Vince Spicer
On Tue, Nov 2, 2010 at 1:07 PM, Glen Clark  wrote:

> sorry:
>
> NumItems = int(input("How many Items: "))
>
>
> Entries = []
> for In in range(0,NumItems):
>   Entries.append("")
>
>
>
> for In in range(0,NumItems):
>   Entries[In]=str(input("Enter name " + str(In+1) + ": "))
>
>
> for In in range(0,NumItems):
>   print(Entries[In])
>
> confirmed = int(input("Are you happy with this? (y/n): ")
>
> if confirmed == "y":
>   for In in range(0,NumItems):
>  print(Entries[In] + ": " + str(In))
>   change = int(input("Which item would you like to change: ")
>   Entries[change]=str(input("Please enter a nem name: ")
> else:
>#do nothing
>
> print(Entries)
>
> On Tue, 2010-11-02 at 15:05 -0400, Alex Hall wrote:
> > On 11/2/10, Glen Clark  wrote:
> > >  File "/home/glen/workspace/test.py", line 19
> > > if confirmed == "y":
> > >^
> > > SyntaxError: invalid syntax
> > >
> > > Why does this not work??? PyDev says "Expected:else"
> > It may help to see the rest of the file, or at least more of the code
> > surrounding this statement.
> > >
> > > ___
> > > 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
>

confirmed = int(input("Are you happy with this? (y/n): ")

You are missing a ) that the end of this line to close the int

-- 
Vince Spicer


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


Re: [Tutor] if statement

2010-11-02 Thread Adam Bark

On 02/11/10 19:07, Glen Clark wrote:

sorry:

NumItems = int(input("How many Items: "))


Entries = []
for In in range(0,NumItems):
Entries.append("")



for In in range(0,NumItems):
Entries[In]=str(input("Enter name " + str(In+1) + ": "))


for In in range(0,NumItems):
print(Entries[In])

confirmed = int(input("Are you happy with this? (y/n): ")

if confirmed == "y":
for In in range(0,NumItems):
   print(Entries[In] + ": " + str(In))
change = int(input("Which item would you like to change: ")
Entries[change]=str(input("Please enter a nem name: ")
else:
 #do nothing

print(Entries)

   

Ok that's easier, you're missing a closing bracket at the end of the

confirmed = int(input("Are you happy with this? (y/n): ")

line.
I think you might need at least a pass after else as well, although it 
should be fine to leave it out altogether once you've added the ')'.


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


Re: [Tutor] if statement

2010-11-02 Thread Glen Clark
I tried that and it still does not work. 

On Tue, 2010-11-02 at 15:13 -0400, James Reynolds wrote:
> the syntax is:
> 
> 
> if True:
>  do something that you want to do if the condition you are testing
> is True, in your case when confirmed is "y"
> elif True:
>  optional: do something else when the above condition is false and
> this condition is True.
> else:
>  do something else when the above conditions are false.
> 
> 
> You can try this,
> 
> 
> if confirmed == "y":
> stuff
> else:
> pass
> 
> 
> 
> 
> On Tue, Nov 2, 2010 at 3:02 PM, Glen Clark  wrote:
>  File "/home/glen/workspace/test.py", line 19
>if confirmed == "y":
>   ^
> SyntaxError: invalid syntax
> 
> Why does this not work??? PyDev says "Expected:else"
> 
> ___
> 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] if statement

2010-11-02 Thread James Reynolds
the syntax is:

if True:
 do something that you want to do if the condition you are testing is
True, in your case when confirmed is "y"
elif True:
 optional: do something else when the above condition is false and this
condition is True.
else:
 do something else when the above conditions are false.

You can try this,

if confirmed == "y":
stuff
else:
pass



On Tue, Nov 2, 2010 at 3:02 PM, Glen Clark  wrote:

>  File "/home/glen/workspace/test.py", line 19
>if confirmed == "y":
>   ^
> SyntaxError: invalid syntax
>
> Why does this not work??? PyDev says "Expected:else"
>
> ___
> 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] if statement

2010-11-02 Thread delegbede
It is not always enough to send just the error. 
What construct do you have after the if line?

Make your sample detailed to get useful responses. 

Regards. 
Sent from my BlackBerry wireless device from MTN

-Original Message-
From: Glen Clark 
Sender: tutor-bounces+delegbede=dudupay@python.org
Date: Tue, 02 Nov 2010 19:02:15 
To: python mail list
Subject: [Tutor] if statement

 File "/home/glen/workspace/test.py", line 19
if confirmed == "y":
   ^
SyntaxError: invalid syntax

Why does this not work??? PyDev says "Expected:else"

___
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] if statement

2010-11-02 Thread Adam Bark

On 02/11/10 19:02, Glen Clark wrote:

  File "/home/glen/workspace/test.py", line 19
 if confirmed == "y":
^
SyntaxError: invalid syntax

Why does this not work??? PyDev says "Expected:else"
   

It's hard to tell without context. Can you send the code around it as well?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if statement

2010-11-02 Thread Glen Clark
sorry:

NumItems = int(input("How many Items: "))


Entries = []
for In in range(0,NumItems):
   Entries.append("")



for In in range(0,NumItems):
   Entries[In]=str(input("Enter name " + str(In+1) + ": "))
   

for In in range(0,NumItems):
   print(Entries[In])

confirmed = int(input("Are you happy with this? (y/n): ")

if confirmed == "y":
   for In in range(0,NumItems):
  print(Entries[In] + ": " + str(In))
   change = int(input("Which item would you like to change: ")   
   Entries[change]=str(input("Please enter a nem name: ")
else:
#do nothing

print(Entries)

On Tue, 2010-11-02 at 15:05 -0400, Alex Hall wrote:
> On 11/2/10, Glen Clark  wrote:
> >  File "/home/glen/workspace/test.py", line 19
> > if confirmed == "y":
> >^
> > SyntaxError: invalid syntax
> >
> > Why does this not work??? PyDev says "Expected:else"
> It may help to see the rest of the file, or at least more of the code
> surrounding this statement.
> >
> > ___
> > 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] if statement

2010-11-02 Thread Alex Hall
On 11/2/10, Glen Clark  wrote:
>  File "/home/glen/workspace/test.py", line 19
> if confirmed == "y":
>^
> SyntaxError: invalid syntax
>
> Why does this not work??? PyDev says "Expected:else"
It may help to see the rest of the file, or at least more of the code
surrounding this statement.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] if statement

2010-11-02 Thread Glen Clark
 File "/home/glen/workspace/test.py", line 19
if confirmed == "y":
   ^
SyntaxError: invalid syntax

Why does this not work??? PyDev says "Expected:else"

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


[Tutor] If statement isn't working

2010-10-29 Thread Susana Iraiis Delgado Rodriguez
Hello members:

I'm trying to validate the existence of a file by an if statement, but it
isn't working correctly. The module is a crawler that writes to excel some
attributes from the files it finds.

folders = None
 # look in this (root) folder for files with specified extension
for root, folders, files in os.walk( "C:\\" ):
   file_list.extend(os.path.join(root,fi) for fi in files if
fi.endswith(".shp"))
wrkbk = Workbook()
 #Add named parameter to allow overwriting cells: cell_overwrite_ok=True
wksht = wrkbk.add_sheet('shp')
#... add the headings to the columns
wksht.row(0).write(0,'ruta')
wksht.row(0).write(1,'archivo')
#write the rows
for row, filepath in enumerate(file_list, start=1):
  wksht.row(row).write(0, filepath)
 (ruta, filename) = os.path.split(filepath)
 wksht.row(row).write(1, filename)

#Here I`m splitting the string filename in base and extension
n = os.path.splitext(filename)
#Getting the base and prj as its extension
 p = n[0]+'.prj'
#validate if p exists
 if os.path.lexists(p):
  wksht.row(row).write(9, 1)
  prj_text = open(p, 'r').read()
  wksht.row(row).write(8,prj_text)
 else:
  wksht.row(row).write(9, 0)
  wksht.row(row).write(8, 'Sin prj, no se puede determinar la proyeccion')

The issue is that it just identifies 3 prj and I have more, befores I
added  prj_text = open(p, 'r').read()
  wksht.row(row).write(8,prj_text) it worked fine and write the correct prj,
but now it doesn't

What am I doing wrong? Hope you can help me
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor