Re: help, please, with 3.10.4 install

2022-05-30 Thread Dennis Lee Bieber
On Sat, 28 May 2022 21:11:00 -0500, Jack Gilbert <00jhen...@gmail.com>
declaimed the following:

>also, the same line: Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022,
>23:13:41) [MSC v.1929 64 bit (AMD64)] on win32 in CMD prompt
>
>for the life of me I can't figure out how to launch python??
>

Well, what did you type in that command shell to get the line you
report above? (Cut and Paste the TEXT from that command shell -- don't just
transcribe by hand). That version string is only displayed when one starts
Python in interactive mode.

-=-=-
Microsoft Windows [Version 10.0.19044.1706]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Wulfraed>python
Python ActivePython 3.8.2 (ActiveState Software Inc.) based on
 on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

-=-=-



-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: help, please, with 3.10.4 install

2022-05-30 Thread Mats Wichmann
On 5/28/22 20:11, Jack Gilbert wrote:
> I downloaded 3.10.4 on a 64 bit , 8.1

> also, the same line: Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022,
> 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32 in CMD prompt
> 
> for the life of me I can't figure out how to launch python??

Sounds like you're launching it already?

In a cmd shell, type:

py


And you should be good to go.  See the page @dn pointed to.


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


Re: help, please, with 3.10.4 install

2022-05-29 Thread dn
On 29/05/2022 14.11, Jack Gilbert wrote:
> I downloaded 3.10.4 on a 64 bit , 8.1
> I can see IDLE shell 3.10.1, I see Python 3.10.4 (tags/v3.10.4:9d38120, Mar
> 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32
> 
> also, the same line: Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022,
> 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32 in CMD prompt
> 
> for the life of me I can't figure out how to launch python??
> 
> I did click add to path in the install
> 
> thanks


Please advise if https://docs.python.org/3/using/windows.html does not
answer the question...
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: HELP Please, Python Program Help

2021-04-10 Thread dn via Python-list
On 10/04/2021 22.57, Joseph Roffey wrote:
> Hi, Im looking for some help with my program, I have been set a task to make 
> a Strain Calculator. I need it to input two numbers, choosing either Metres 
> or Inches for the 'Change in Length' divided by the 'Original Length' which 
> can also be in Metres or Inches, the out put number also needs to give an 
> option for the answer to be in metres or inches.
> 
> this is what i have come up with so far...

What is the problem?


> txt = "Strain Calculator"
> x = txt.title()

what is the above/


> print(x)
> 
> # This function divides two numbers
> def divide(x, y):
>   return x / y

Why use a function instead of operating in-line?

-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help Please

2021-03-28 Thread D'Arcy Cain

On 2021-03-26 12:42 p.m., Igor Korot wrote:

On top of that - usual stanza applies:

1. OS - Windows, Linux, Mac?
2. OS version?
3. Python version?
4. Are you able to run python interpretor?
5. Socks version you are trying to install?
6. Was install successful?


7. Use a subject that describes the actual issue.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help Please

2021-03-26 Thread Igor Korot
Hi,

On Fri, Mar 26, 2021 at 11:36 AM Anis4Games  wrote:

> Hello python support team , i need help about packages and python modules
>
> That Video Will Explain My Problem
>

Please don't send any attachment to the list - it will be dropped from the
E-mail.

Cut'n'paste any errors you receive directly in the body of the message.

On top of that - usual stanza applies:

1. OS - Windows, Linux, Mac?
2. OS version?
3. Python version?
4. Are you able to run python interpretor?
5. Socks version you are trying to install?
6. Was install successful?

Thank you.


> The Problem : Is Im Installed [Socks] Alredy With Command => pip install
> socks
>
> But When i run some script using socks pack its show a error with message "
> import socks " no socks modules found
>
> So Please Help Me
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help please installing Python on Windows 10

2018-10-04 Thread Sibylle Koczian

Am 03.10.2018 um 09:34 schrieb Timothy Cowell via Python-list:

Could I please ask for help installing Python on Windows 10 - I've tried twice 
(Version 3.7 for windows) selecting the install now option. After first attempt 
I uninstalled and tried again.

Each time it has put 4 items in the programs list from the windows start 
button, all under heading Python 3.7, but the first time they said 64 bit and 
the second time only 32 bit - I guess I must have clicked on different versions.

32 bit on a 64 bit PC and Windows version should work, 64 bit on 32 bit 
Windows probably not. So, if you kept your second attempt, that should 
be enough to start with.


Both times there was IDLE, Python 3.7, Manuals, and Module Docs. The last two 
of these worked when clicked on, but the first two just put up a small window 
of which first was white, and second was black, but I couldn't make them do 
anything.


IDLE and the Python shell both start with windows showing text like this:

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 
bit (AMD64)] on win32

Type "copyright", "credits" or "license()" for more information.
>>>

Did you get something like this? In that case nothing was wrong, Python 
just waited for your commands. The manual contains a tutorial which 
starts using the interactive interpreter - try it out. If you don't get 
the results the tutorial predicts, come back here or subscribe to the 
tutor list:

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

If your "small windows" don't contain such a header, that really would 
look wrong. In that case: are they completely empty? Or what else? If 
they contain any text at all, can you copy and paste it into your 
answer? Please don't try to send a screenshot, the list won't accept it.


HTH
Sibylle





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


Re: Help Please ! Undocumented ERROR message so dont know how to fix the problem

2017-05-03 Thread Stephen Tucker
To murdock: What Rhodri wrote is correct. I sense that it might be helpful
for you if I were to tell you that there is a difference between a function
and a function call. If your function were named

MyFunction

then

print (MyFunction)

would print a user-friendly-ish message about the function. This message
tells you (a) that the object you are asking Python to print is a function,
and (b) the address (in hexadecimal) in memory where the code for
MyFunction is stored. This is what your code is doing - hence the message
from Python.

If, on the other hand you have

print (MyFunction(any-parameters-to-MyFunction-with-commas-between-them))

then Python would recognise that (a) you are wanting it to call MyFunction
with the specified parameters, if any, (b) you are expecting that the
function will return a printable result, and (c) you are also expecting it
to print that result.

So, in order to get Python to do that, all you need to do is:

(1) to add the parentheses after the function name in the print statement [
so print (MyFunction) becomes print (MyFunction()) ];

(2) If your function has any parameters, add them, separated with commas,
between the parentheses [ so print (MyFunction()) becomes print
(MyFunction(parameters-separated-with-commas)) ];

(3) and rerun the new code - which should then do what you are wanting it
to do.

I hope this helps.

Stephen Tucker.










Virus-free.
www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Tue, May 2, 2017 at 2:11 PM, Rhodri James  wrote:

> On 02/05/17 03:57, murdock wrote:
>
>> I am having a problem that seems to persist. I have written a program
>> that makes a mathematical calculation and uses a uses library that I have
>> written. It had been working but somehow in playing around with it, it
>> stoppedgo figure!  But here is the thing, when I run the program it
>> gives me a very ambiguous message with only a string as in:
>>
>> "The Receiver Noise Figure =  > 0x063E5A60>  dBm"
>>
>
> This is not an error message.  This is Python faithfully printing out what
> you asked it to print out.  Here's the line that does the printing:
>
> print ("The Receiver Noise Figure = ",Hamath._Noise_Figure," dBm" )
>
> The weird-looking bit of the message is the representation of a function,
> and lo! in the parameters to print() there is the function
> Hamath._Noise_Figure.  Note that this is the function itself, *not* the
> result of calling it, since you *don't* call it.
>
> --
> Rhodri James *-* Kynesim Ltd
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help Please ! Undocumented ERROR message so dont know how to fix the problem

2017-05-02 Thread Rhodri James

On 02/05/17 03:57, murdock wrote:

I am having a problem that seems to persist. I have written a program that 
makes a mathematical calculation and uses a uses library that I have written. 
It had been working but somehow in playing around with it, it stoppedgo 
figure!  But here is the thing, when I run the program it gives me a very 
ambiguous message with only a string as in:

"The Receiver Noise Figure =
dBm"


This is not an error message.  This is Python faithfully printing out 
what you asked it to print out.  Here's the line that does the printing:


print ("The Receiver Noise Figure = ",Hamath._Noise_Figure," dBm" )

The weird-looking bit of the message is the representation of a 
function, and lo! in the parameters to print() there is the function 
Hamath._Noise_Figure.  Note that this is the function itself, *not* the 
result of calling it, since you *don't* call it.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help Please ! Undocumented ERROR message so dont know how to fix the problem

2017-05-02 Thread Steve D'Aprano
On Tue, 2 May 2017 12:57 pm, murdock wrote:

> I am having a problem that seems to persist. I have written a program that
> makes a mathematical calculation and uses a uses library that I have
> written. It had been working but somehow in playing around with it, it
> stoppedgo figure!  But here is the thing, when I run the program it
> gives me a very ambiguous message with only a string as in:
> 
> "The Receiver Noise Figure =   0x063E5A60>  dBm"

That is absolutely not a Python error message.

There are two sorts of Python error messages: tracebacks, and segmentation
faults. You should never see  segmentation fault (if you do, it is a bug or
corruption in the Python interpreter) but if you do, there may not even be
message aside from "Segmentation fault". So forget all about them.

The only sort of Python error message you are likely to see is a traceback,
which looks like this:

Traceback (most recent call last):
  File "", line 1, in 
ValueError: not enough values to unpack (expected 2, got 1)


There may be more lines between the "Traceback" line and the last line,
which will be the actual error. It may not be ValueError, it could be
TypeError, AttributeError, IndexError, or many other things.

> now the program is being run under PyScripter

What happens if you *don't* run the program under PyScripter?

It looks to me that PyScripter is trying to be "helpful" by hiding the
actual error message from you, and perhaps showing you some random
diagnostic, or the line of code that failed.

Of course that's not helpful at all. See if you can run the script without
involving PyScripter. The easiest way is to enter the following at a
terminal or console:

python myscript.py

Replace the "myscript.py" with the actual name of your Python .py file.



> I am told that the error message is NOT an PyScripter error but in fact a
> Python message. 

Who told you this? I'm pretty sure they're wrong.

Unless they are going by more information than you've told us.


-- 
Steve
Emoji: a small, fuzzy, indistinct picture used to replace a clear and
perfectly comprehensible word.

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


Re: Help Please ! Undocumented ERROR message so dont know how to fix the problem

2017-05-02 Thread Gregory Ewing

murdock wrote:

BW = float (input ("Enter the Receiver Bandwidth in Hz"))
Signal_to_Noise = float (input ("Enter the Signal to Noise in dB"))
RX_Sensitivity = float (input ("Enter the RX_Sensitivity in dBm"))
#
print ("The Receiver Noise Figure = ",Hamath._Noise_Figure," dBm" )


I'm guessing you intend the three values you calculate to be
passed as parameters to the function:

   print("The Receiver Noise Figure = ", Hamath._Noise_Figure(BW, 
Signal_to_Noise, RX_Sensitivity), " dBm")


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


Re: Help Please ! Undocumented ERROR message so dont know how to fix the problem

2017-05-01 Thread Michael Torrie
On 05/01/2017 08:57 PM, murdock wrote:
> I am having a problem that seems to persist. I have written a program that 
> makes a mathematical calculation and uses a uses library that I have written. 
> It had been working but somehow in playing around with it, it stoppedgo 
> figure!  But here is the thing, when I run the program it gives me a very 
> ambiguous message with only a string as in:
> 
> "The Receiver Noise Figure =
> dBm"  

> import Hamath
> import math
>
> def main():
> #import math
>
> BW = float (input ("Enter the Receiver Bandwidth in Hz"))
> Signal_to_Noise = float (input ("Enter the Signal to Noise in dB"))
> RX_Sensitivity = float (input ("Enter the RX_Sensitivity in dBm"))
> #
> print ("The Receiver Noise Figure = ",Hamath._Noise_Figure," dBm" )
> if __name__ == '__main__':
> main()

Hamaht._Noise_Figure is a function.  In fact you said so yourself.  But
you're not calling it, nor is your code doing anything with the RW and
Signal_to_Noise variables.

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


Re: HELP PLEASE printing single characters!

2015-12-03 Thread Larry Hudson via Python-list

On 12/02/2015 04:08 PM, John Strick wrote:

On Wednesday, December 2, 2015 at 12:58:30 PM UTC-6, Dylan Riley wrote:

hi all,
I have been trying to figure out all day why my code is printing single 
characters from my list when i print random elements using random.choice the 
elements in the list are not single characters for example when i print, 
print(LIST[random.choice]) i get:
["e", "x", "a", "m", "p", "l", "e"] when i should get ["example"].

my code is:
#Create a program that prints a list of words in random order.
#The program should print all the words and not repeat any.

import random

LIST = ["blue ", "red ", "yellow ", "green ", "orange "]
order = []

print("This game will print a random order of colours")
print("The list is", LIST)
input("press enter to start")



while LIST != []:
 choice = random.choice(LIST)
 order += choice
 while choice in LIST:
 LIST.remove(choice)
print(order)



input("press enter to exit")

thanks in advance guys


You could just shuffle the list first, then loop through it. This will 
guarantee that each color is only used once.


Not quite.  Only if the original list has no repetitions.

My personal approach would be to use a set to eliminate the duplicates, convert back to a list 
and shuffle that.


no_reps = list(set(LIST))
random.shuffle(no_reps)
print(no_reps)   #  Or use loop to print one-per-line

 -=- Larry -=-

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


Re: HELP PLEASE printing single characters!

2015-12-02 Thread Ian Kelly
On Wed, Dec 2, 2015 at 1:44 PM, Dylan Riley  wrote:
> hi ian what would be the correct code to use in this situation then because 
> as far as i am aware the elements of my list should be printed as whole 
> elements and not just characters of the elements.

order.append(choice)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: HELP PLEASE printing single characters!

2015-12-02 Thread Ian Kelly
On Wed, Dec 2, 2015 at 12:58 PM, Dylan Riley  wrote:
> hi all,
> I have been trying to figure out all day why my code is printing single 
> characters from my list when i print random elements using random.choice the 
> elements in the list are not single characters for example when i print, 
> print(LIST[random.choice]) i get:
> ["e", "x", "a", "m", "p", "l", "e"] when i should get ["example"].

Remember that strings are iterable, and that iterating over strings
results in individual characters. That should give you a clue as to
what's going on.

> my code is:
> #Create a program that prints a list of words in random order.
> #The program should print all the words and not repeat any.
>
> import random
>
> LIST = ["blue ", "red ", "yellow ", "green ", "orange "]
> order = []
>
> print("This game will print a random order of colours")
> print("The list is", LIST)
> input("press enter to start")
>
>
>
> while LIST != []:
> choice = random.choice(LIST)
> order += choice

Addition on a list does concatenation, not appending. So this takes
each element from choice and adds them individually to order.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: HELP PLEASE printing single characters!

2015-12-02 Thread Dylan Riley
On Wednesday, December 2, 2015 at 7:09:23 PM UTC, Ian wrote:
> On Wed, Dec 2, 2015 at 12:58 PM, Dylan Riley  wrote:
> > hi all,
> > I have been trying to figure out all day why my code is printing single 
> > characters from my list when i print random elements using random.choice 
> > the elements in the list are not single characters for example when i 
> > print, print(LIST[random.choice]) i get:
> > ["e", "x", "a", "m", "p", "l", "e"] when i should get ["example"].
> 
> Remember that strings are iterable, and that iterating over strings
> results in individual characters. That should give you a clue as to
> what's going on.
> 
> > my code is:
> > #Create a program that prints a list of words in random order.
> > #The program should print all the words and not repeat any.
> >
> > import random
> >
> > LIST = ["blue ", "red ", "yellow ", "green ", "orange "]
> > order = []
> >
> > print("This game will print a random order of colours")
> > print("The list is", LIST)
> > input("press enter to start")
> >
> >
> >
> > while LIST != []:
> > choice = random.choice(LIST)
> > order += choice
> 
> Addition on a list does concatenation, not appending. So this takes
> each element from choice and adds them individually to order.

hi ian what would be the correct code to use in this situation then because as 
far as i am aware the elements of my list should be printed as whole elements 
and not just characters of the elements.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: HELP PLEASE printing single characters!

2015-12-02 Thread John Strick
On Wednesday, December 2, 2015 at 12:58:30 PM UTC-6, Dylan Riley wrote:
> hi all,
> I have been trying to figure out all day why my code is printing single 
> characters from my list when i print random elements using random.choice the 
> elements in the list are not single characters for example when i print, 
> print(LIST[random.choice]) i get:
> ["e", "x", "a", "m", "p", "l", "e"] when i should get ["example"].
> 
> my code is:
> #Create a program that prints a list of words in random order.
> #The program should print all the words and not repeat any.
> 
> import random
> 
> LIST = ["blue ", "red ", "yellow ", "green ", "orange "]
> order = []
> 
> print("This game will print a random order of colours")
> print("The list is", LIST)
> input("press enter to start")
> 
> 
> 
> while LIST != []:
> choice = random.choice(LIST)
> order += choice
> while choice in LIST:
> LIST.remove(choice)
> print(order)
> 
> 
> 
> input("press enter to exit")
> 
> thanks in advance guys

You could just shuffle the list first, then loop through it. This will 
guarantee that each color is only used once. 

import random
LIST = ["blue ", "red ", "yellow ", "green ", "orange "]
random.shuffle(LIST)
for color in LIST:
print(color)
# or add to order or whatever you need to

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


Re: help please: tkinter grid layout is very slow

2014-11-13 Thread Terry Reedy

On 11/13/2014 3:45 PM, Rich Cook wrote:

Hi, I'm trying to toss together an image browser in tkinter, and it is so slow 
it is unworkable.  Here is my code.  Can someone point out why it's so slw? 
 :-)  Thanks

root = Tkinter.Tk()
root.geometry(1000x280+300+300)
label = Tkinter.Button(root, compound=Tkinter.TOP)
label.pack()

numimages = len(image_list)
numcols = 6
numrows = numimages/numcols


That should be numimages // numcols


if numrows * numcols != numimages:
 numrows += 1

frame = Tkinter.Frame(root)
for col in range(numcols):
 frame.columnconfigure(col, pad=2)

for row in range(numrows):
 frame.rowconfigure(row, pad=2)

print There are, numimages, images  # 256 in fact...
for imagenum, (row, col) in enumerate([(row,col) for row in range(numrows) for 
col in range(numcols)]):
 b = Tkinter.Label(frame, compound = Tkinter.TOP)
 b['text'] = os.path.basename(image_list[imagenum])
 b['image'] = ImageTk.PhotoImage(Image.open(image_list[imagenum]) )


ImageTk? or Tkinter?


 b.grid(row=row, column = col)

frame.pack()

root.mainloop()




--
Terry Jan Reedy

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


Re: help please: tkinter grid layout is very slow

2014-11-13 Thread Chris Angelico
On Fri, Nov 14, 2014 at 7:45 AM, Rich Cook wealthyc...@gmail.com wrote:
 print There are, numimages, images  # 256 in fact...
 for imagenum, (row, col) in enumerate([(row,col) for row in range(numrows) 
 for col in range(numcols)]):
 b = Tkinter.Label(frame, compound = Tkinter.TOP)
 b['text'] = os.path.basename(image_list[imagenum])
 b['image'] = ImageTk.PhotoImage(Image.open(image_list[imagenum]) )

You're asking someone somewhere to load 256 images into memory and
display them. What's the resolution of these images? Do they need to
be scaled/cropped? That can be fairly expensive. How long does it
actually take to (a) load all those images, and (b) pack the frame?
Try, for instance, commenting out the b.grid() call, to force them all
to be loaded but not packed.

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


Re: Help please, why doesn't it show the next input?

2013-09-13 Thread William Bryant
On Thursday, September 12, 2013 9:39:33 PM UTC+12, Oscar Benjamin wrote:
 On 12 September 2013 07:04, William Bryant gogobe...@gmail.com wrote:
 
  Thanks everyone for helping but I did listen to you :3 Sorry. This is my 
  code, it works, I know it's not the best way to do it and it's the long way 
  round but it is one of my first programs ever and I'm happy with it:
 
 
 
 Hi William, I'm glad you've solved your initial problem and I just
 
 wanted to make a couple of comments about how your program could be
 
 simplified or improved. The comments are below.
 

Hello, I've done this so far but why doesn't the mode function work?

'''#*'''
#* Name:Mode-Median-Mean Calculator   *#
#**#
#* Purpose: To calculate the mode, median and mean of a list of numbers   *#
#*  and the mode of a list of strings because that is what we are *#
#*  learning in math atm in school :P *#
#**#
#* Author:  William Bryant*#
#**#
#* Created: 11/09/2013*#
#**#
#* Copyright:   (c) William 2013  *#
#**#
#* Licence: IDK :3*#
'''**'''




#-#   ~~Import things I am using~~   #-#

# |
#|
#   \/

import time
import itertools



#-#~~Variables that I am using, including the list.~~#-#

# |
#|
#   \/

List = []
NumberOfXItems = []
Themode = []

#-#   ~~Functions that I am using.~~ #-#

# |
#|
#   \/

def HMNs():
global TheStr, user_inputHMNs, List_input, List
user_inputHMNs = input(You picked string. This program cannot calculate 
the mean or median, but it can calculate the mode. :D  How many strings are you 
using in your list? (Can not be a decimal number)  \nEnter:  )
user_inputHMNs
time.sleep(1.5)
TheStr = int(user_inputHMNs)
for i in range(TheStr):
List_input = input(Enter your strings. (One in each input field):  )
List.append(List_input)
print(Your list - , List)
if List.count == int(user_inputHMNs):
break
mode()

def HMNn():
global TheNum, user_inputHMNn, List_input, List
user_inputHMNn = input(You picked number. :D How many numbers are you 
using in your list? (Can not be a decimal number) \nEnter:  )
user_inputHMNn
time.sleep(1.5)
TheNum = int(user_inputHMNn)
for i in range(TheNum):
List_input = input(Enter your numbers. (One in each input field):  )
List_input = int(List_input)
List.append(List_input)
print(Your list - , List)
if List.count == int(user_inputHMNn):
break
mode()
def NOS():
while True: # Loops forever (until the break)
answer = input(Does your list contain a number or a string?  \nEnter: 
)
answer = answer.lower()
if answer in (string, str, s):
HMNs()
break
elif answer in (number, num, n, int):
HMNn()
break
elif answer in (quit, q):
break  # Exits the while loop
else:
print(You did not enter a valid field, :P Sorry.  \nEnter: )
time.sleep(1.5)

def mode():
global NumberOfXItems, Themode
for i in List:
NumberOfXItems.append(i)
NumberOfXItems.append(List.count(i))
Themode = max(NumberOfXItems)
print(Themode)



#-#   ~~The functions which need calling~~   #-#

# |
#|
#   \/

NOS()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help please, why doesn't it show the next input?

2013-09-13 Thread John Gordon
In 364bcdb3-fdd5-4774-b7d2-040e2ccb4...@googlegroups.com William Bryant 
gogobe...@gmail.com writes:

 Hello, I've done this so far but why doesn't the mode function work?

 def mode():
 global NumberOfXItems, Themode
 for i in List:
 NumberOfXItems.append(i)
 NumberOfXItems.append(List.count(i))
 Themode = max(NumberOfXItems)
 print(Themode)

As far as I can see, you're appending each of the user's numbers onto
NumberOfXItems, and you're also appending the number of times each number
occurs.

So, if the user had entered these numbers:

5 9 9 9 15 100 100

NumberOfXItems would end up looking like this:

5 1 9 3 9 3 9 3 15 1 100 2 100 2

The max is 100, but 9 is the most often-occuring number.

Also, since NumberOfXItems mixes user input and the counts of that input,
you risk getting a max that the user didn't even enter.  For example if the
user entered these numbers:

1 1 1 1 1 1 2 3

NumberOfXItems would end up looking like this:

1 6 1 6 1 6 1 6 1 6 1 6 2 1 3 1

The max is 6, which is a count, not user input.

mode would be much better written like this:

  def mode(mylist):

  max_occurrences = 0
  themode = None

  for i in mylist:
  thecount = mylist.count(i)
  if thecount  max_occurrences:
  max_occurrences = thecount
  themode = i

  print(themode)

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

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


Re: Help please, why doesn't it show the next input?

2013-09-13 Thread MRAB

On 13/09/2013 23:12, William Bryant wrote:

On Thursday, September 12, 2013 9:39:33 PM UTC+12, Oscar Benjamin wrote:

On 12 September 2013 07:04, William Bryant gogobe...@gmail.com wrote:

 Thanks everyone for helping but I did listen to you :3 Sorry. This is my 
code, it works, I know it's not the best way to do it and it's the long way round 
but it is one of my first programs ever and I'm happy with it:



Hi William, I'm glad you've solved your initial problem and I just

wanted to make a couple of comments about how your program could be

simplified or improved. The comments are below.



Hello, I've done this so far but why doesn't the mode function work?

'''#*'''
#* Name:Mode-Median-Mean Calculator   *#
#**#
#* Purpose: To calculate the mode, median and mean of a list of numbers   *#
#*  and the mode of a list of strings because that is what we are *#
#*  learning in math atm in school :P *#
#**#
#* Author:  William Bryant*#
#**#
#* Created: 11/09/2013*#
#**#
#* Copyright:   (c) William 2013  *#
#**#
#* Licence: IDK :3*#
'''**'''




#-#   ~~Import things I am using~~   #-#

# |
#|
#   \/

import time
import itertools



#-#~~Variables that I am using, including the list.~~#-#

# |
#|
#   \/


Global variables and no parameter passing: yuck! :-)


List = []
NumberOfXItems = []
Themode = []

#-#   ~~Functions that I am using.~~ #-#

# |
#|
#   \/


Your function names aren't meaningful.


def HMNs():
 global TheStr, user_inputHMNs, List_input, List
 user_inputHMNs = input(You picked string. This program cannot calculate the 
mean or median, but it can calculate the mode. :D  How many strings are you using in your 
list? (Can not be a decimal number)  \nEnter:  )


This line doesn't do anything:


 user_inputHMNs
 time.sleep(1.5)


This variable is an integer, yet it's called 'TheStr'.


 TheStr = int(user_inputHMNs)
 for i in range(TheStr):
 List_input = input(Enter your strings. (One in each input field):  )
 List.append(List_input)
 print(Your list - , List)


Here you're comparing the list's .count method with an integer. It'll 
never be true!



 if List.count == int(user_inputHMNs):
 break
 mode()

def HMNn():
 global TheNum, user_inputHMNn, List_input, List
 user_inputHMNn = input(You picked number. :D How many numbers are you using in 
your list? (Can not be a decimal number) \nEnter:  )
 user_inputHMNn
 time.sleep(1.5)
 TheNum = int(user_inputHMNn)
 for i in range(TheNum):
 List_input = input(Enter your numbers. (One in each input field):  )
 List_input = int(List_input)
 List.append(List_input)
 print(Your list - , List)


The same bug as above:


 if List.count == int(user_inputHMNn):
 break
 mode()
def NOS():
 while True: # Loops forever (until the break)
 answer = input(Does your list contain a number or a string?  \nEnter: 
)
 answer = answer.lower()
 if answer in (string, str, s):
 HMNs()
 break
 elif answer in (number, num, n, int):
 HMNn()
 break
 elif answer in (quit, q):
 break  # Exits the while loop
 else:
 print(You did not enter a valid field, :P Sorry.  \nEnter: )
 time.sleep(1.5)

def mode():
 global NumberOfXItems, Themode
 for i in List:


Here you're appending an item and then the number of times that the item 
occurs:



 NumberOfXItems.append(i)
 NumberOfXItems.append(List.count(i))


Here you're getting the maximum entry, be it an item or the number of 
times an item occurs (see above). Have a look at the Counter class from 
the collections module:



 Themode = max(NumberOfXItems)
 print(Themode)



#-#   ~~The functions which need calling~~   #-#

# |
#|
#   \/

NOS()



--

Re: Help please, why doesn't it show the next input?

2013-09-13 Thread William Bryant
Thanks for the contructive critisism - :D I'll try fix it up!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help please, why doesn't it show the next input?

2013-09-12 Thread William Bryant
Thanks everyone for helping but I did listen to you :3 Sorry. This is my code, 
it works, I know it's not the best way to do it and it's the long way round but 
it is one of my first programs ever and I'm happy with it:

'''#*'''
#* Name:Mode-Median-Mean Calculator   *#
#**#
#* Purpose: To calculate the mode, median and mean of a list of numbers   *#
#*  and the mode of a list of strings because that is what we are *#
#*  learning in math atm in school :P *#
#**#
#* Author:  William Bryant*#
#**#
#* Created: 11/09/2013*#
#**#
#* Copyright:   (c) William 2013  *#
#**#
#* Licence: IDK :3*#
'''**'''




#-#   ~~Import things I am using~~   #-#

# |
#|
#   \/

import time
import itertools



#-#~~Variables that I am using, including the list.~~#-#

# |
#|
#   \/

num_or_string = None
amount_numbers = []
List = []
prompt = Does your list contain, a number or a string?  \nEnter:  
user_inputHMNn = None
user_inputHMNs = None

#-#   ~~Functions that I am using.~~ #-#

# |
#|
#   \/

user_inputNOS = input(prompt)
user_inputNOS
time.sleep(1.5)

def NOS():
if user_inputNOS == String or user_inputNOS == string or user_inputNOS 
== STRING or user_inputNOS == s or user_inputNOS == S or user_inputNOS == 
str:
HMNs()
elif user_inputNOS == Number or user_inputNOS == number or 
user_inputNOS == NUMBER or user_inputNOS == N or user_inputNOS == N or 
user_inputNOS == int or user_inputNOS == num:
HMNn()
else:
global user_inputNOS2
global prompt
prompt = You did not enter a valid field, :P Sorry.  \nEnter:  
user_inputNOS2 = input(prompt)
user_inputNOS2
time.sleep(1.5)
NOS2()

def NOS2():
if user_inputNOS2 == String or user_inputNOS2 == string or 
user_inputNOS2 == STRING or user_inputNOS2 == s or user_inputNOS2 == S or 
user_inputNOS2 == str:
HMNs()
elif user_inputNOS2 == Number or user_inputNOS2 == number or 
user_inputNOS2 == NUMBER or user_inputNOS2 == N or user_inputNOS2 == N or 
user_inputNOS2 == int or user_inputNOS2 == num:
HMNn()
else:
global prompt
prompt = You did not enter a valid field, :P Sorry.  \nEnter:  
user_inputNOS2
time.sleep(1.5)
NOS2()

def HMNs():
global TheStr, user_inputHMNs, List_input
user_inputHMNs = input(You picked string. This program cannot calculate 
the mean or median, but it can calculate the mode. :D  How many strings are you 
using in your list? (Can not be a decimal number)  \nEnter:  )
user_inputHMNs
time.sleep(1.5)
TheStr = int(user_inputHMNs)
for i in range(TheStr):
List_input = input(Enter your strings. (One in each input field):  )
List.append(List_input)
print(Your list - , List)

def HMNn():
global TheNum, user_inputHMNn, List_input
user_inputHMNn = input(You picked number. :D How many numbers are you 
using in your list? (Can not be a decimal number) \nEnter:  )
user_inputHMNn
time.sleep(1.5)
TheNum = int(user_inputHMNn)
for i in range(TheNum):
List_input = input(Enter your numbers. (One in each input field):  )
List.append(List_input)
print(Your list - , List)


#-#   ~~The functions which need calling~~   #-#

# |
#|
#   \/

NOS()


Not done. I'll finish it today! :) Oh and thanks so much for helping, you guys 
are really nice :D Thanks a lot.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help please, why doesn't it show the next input?

2013-09-12 Thread Oscar Benjamin
On 12 September 2013 07:04, William Bryant gogobe...@gmail.com wrote:
 Thanks everyone for helping but I did listen to you :3 Sorry. This is my 
 code, it works, I know it's not the best way to do it and it's the long way 
 round but it is one of my first programs ever and I'm happy with it:

Hi William, I'm glad you've solved your initial problem and I just
wanted to make a couple of comments about how your program could be
simplified or improved. The comments are below.


 '''#*'''
 #* Name:Mode-Median-Mean Calculator   
 *#
 #*
 *#
 #* Purpose: To calculate the mode, median and mean of a list of numbers   
 *#
 #*  and the mode of a list of strings because that is what we are 
 *#
 #*  learning in math atm in school :P 
 *#
 #*
 *#
 #* Author:  William Bryant
 *#
 #*
 *#
 #* Created: 11/09/2013
 *#
 #*
 *#
 #* Copyright:   (c) William 2013  
 *#
 #*
 *#
 #* Licence: IDK :3
 *#
 '''**'''




 #-#   ~~Import things I am using~~   
 #-#

 # |
 #|
 #   \/

 import time
 import itertools



 #-#~~Variables that I am using, including the list.~~
 #-#

 # |
 #|
 #   \/

 num_or_string = None
 amount_numbers = []
 List = []
 prompt = Does your list contain, a number or a string?  \nEnter:  
 user_inputHMNn = None
 user_inputHMNs = None

Of the declarations above only List and prompt are needed. Actually
though I wouldn't use either of those. List should really be a local
variable inside the functions below. And it would be better to write
prompt inline e.g.:

answer = input(Does your list contain, a number or a string?  \nEnter:  )

That makes it easier to understand what's happening when you look at
the code. So I would remove all of those variable declarations. In
some other programming languages there are reasons to use declarations
like those above but not in Python.


 #-#   ~~Functions that I am using.~~ 
 #-#

 # |
 #|
 #   \/

 user_inputNOS = input(prompt)
 user_inputNOS
 time.sleep(1.5)

 def NOS():
 if user_inputNOS == String or user_inputNOS == string or 
 user_inputNOS == STRING or user_inputNOS == s or user_inputNOS == S or 
 user_inputNOS == str:
 HMNs()
 elif user_inputNOS == Number or user_inputNOS == number or 
 user_inputNOS == NUMBER or user_inputNOS == N or user_inputNOS == N or 
 user_inputNOS == int or user_inputNOS == num:
 HMNn()
 else:
 global user_inputNOS2
 global prompt
 prompt = You did not enter a valid field, :P Sorry.  \nEnter:  
 user_inputNOS2 = input(prompt)
 user_inputNOS2
 time.sleep(1.5)
 NOS2()

 def NOS2():
 if user_inputNOS2 == String or user_inputNOS2 == string or 
 user_inputNOS2 == STRING or user_inputNOS2 == s or user_inputNOS2 == S 
 or user_inputNOS2 == str:
 HMNs()
 elif user_inputNOS2 == Number or user_inputNOS2 == number or 
 user_inputNOS2 == NUMBER or user_inputNOS2 == N or user_inputNOS2 == N 
 or user_inputNOS2 == int or user_inputNOS2 == num:
 HMNn()
 else:
 global prompt
 prompt = You did not enter a valid field, :P Sorry.  \nEnter:  
 user_inputNOS2
 time.sleep(1.5)
 NOS2()

The functions above are almost identical. The main difference is just
that NOS2() doesn't call input() which I assume is accidental. So you
could simplify this by only having one function NOS() and having it
call itself rather than NOS2() at the end. Then it would look like:

def NOS():
# code here ...
NOS()

However this is not a common way to use recursive function calls. What
this really does is repeat something forever in a loop. The common way
to do this is to use a for-loop or a while-loop. For example you can
get the same effect with:

while True:  # Loops forever (until the break)
answer = input(Does your list contain, a number or a string?  \nEnter: )
answer = answer.lower()
if answer in (string, str, s):
HMNs()
elif answer in (number, num, n, int):
HMNn()
elif answer in (quit, q):
break  # Exits 

Re: Help please, why doesn't it show the next input?

2013-09-11 Thread Jugurtha Hadjar

Hello, William


On 09/11/2013 06:39 AM, William Bryant wrote:
  user_input1 = input(prompt)

I take it you are using Python 3.x . If that's not the case, take a look 
at raw_input().





def NOS():
 if user_input1 == String or user_input1 == string or user_input1 == STRING or user_input1 == 
s or user_input1 == S or user_input1 == str:
 print(a)



What if you create a list containing these, and then you check if the 
user_input is contained in that list. But before that, get the 
lower-case of it so you don't deal with String sTring string, s, S, etc...


Something like this

You add this to the variables you are using section

string_list = ['string', 's']



When you want to check the check

if user_input.lower() in string_list:
{your_code_here}



 elif user_input1 == Number or user_input1 == number or user_input1 == NUMBER or user_input1 == N 
or user_input1 == N or user_input1 == int or user_input1 == num:
 print(a)



Same goes with that


But some questions:

1 - Why does the user have to specify that, why doesn't the program 
itself tell if it is a string or a number ? You just give it the data 
and it's up to him to tell.


2 - What is it you are trying to accomplish: Maybe there are shortcuts 
or better ways to do things.






--
~Jugurtha Hadjar,
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help please, why doesn't it show the next input?

2013-09-11 Thread Dave Angel
On 11/9/2013 01:39, William Bryant wrote:

 On Wednesday, September 11, 2013 5:11:23 PM UTC+12, John Gordon wrote:
 In ef8de6db-5f35-4d07-8306-bcec47b1e...@googlegroups.com William Bryant 
 gogobe...@gmail.com writes:
 
 
 
  Hey, I am very new to python, I am 13 years old. I want to be able to make 
  =
 
  a program the caculates the mean, meadian and mode. When i run the 
  program,=
 
   an input field pops up and says 'Does your list contain, a number or a 
  str=
 
  ing?' like I want it to, but when I type in something that is not one of 
  va=
 
  lid field options: String or string or STRING or s or S or str 
  =

etc.

Thanks for quoting some context.  However, since you're using buggy
googlegroups, please either constrain your quoting to a couple of lines,
or fix its display to NOT doublespace everything.

See  http://wiki.python.org/moin/GoogleGroupsPython



 Thanks so much for putting your time into helping me!! It worked! Could you 
 tell me if I did anything wrong this time? :)

 #-   Variables that I am using, including the list.  
 -#

 num_or_string = 
 amount_numbers = []
 List = []
 prompt = Does your list contain, a number or a string?

 #-  Functions that I am using.
 -#
 user_input1 = input(prompt)
 user_input1

This last line does nothing useful.  You may be confused because in the
debugger, a lone expression getes its value printed.  But that's a
debugger feature not a language one.  If you want to see what got
input, you'd want to use print() function.


Looks like the second function is identical to the first.  if I'm right,
then just change the NOS2 into NOS1, and save lots of redundancy.


 def NOS():
 if user_input1 == String or user_input1 == string or user_input1 == 
 STRING or user_input1 == s or user_input1 == S or user_input1 == str:
 print(a)
 elif user_input1 == Number or user_input1 == number or user_input1 == 
 NUMBER or user_input1 == N or user_input1 == N or user_input1 == int 
 or user_input1 == num:
 print(a)
 else:
 global user_input2
 global prompt
 prompt = You did not enter a valid field, :P Sorry.
 user_input2 = input(prompt)
 user_input2
 NOS2()

Here you're using the recursive call to NOS() to substitute for a loop. 
Recursion is very useful, but in this case, it hides what's really
happening, and it prevents you from writing a conventional function with
parameters and return value.

I don't know what NOS is supposed to stand for, but it's generally
useful if a function does a simply described single thing.  In this
case, it gets input from the user, and asks the user repeatedly till
he/she gets it right.  So the function should do its own input, and not
expect the top-level code to already have asked once.

Something like:

SOMETHING = [    list of the valid inputs  ]

def query_user(prompt):
while true:
udata = input(prompt)
ifudata.lower() in SOMETHING
return udata
print(Invalid field, sorry)

And now you call this function the same way you would have called
input() function:

user_input1 = query_user(Does your list contain, a number or a
string?)



 NOS()

-- 
DaveA

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


Re: Help please, why doesn't it show the next input?

2013-09-11 Thread William Bryant
@Dave Angel

What is .lower() ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help please, why doesn't it show the next input?

2013-09-11 Thread William Bryant
@Jugurtha Hadjar
What does user_input.lower() mean/do?



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


Re: Help please, why doesn't it show the next input?

2013-09-11 Thread John Gordon
In f7db6733-0f7a-4b18-bdcd-8d53e3644...@googlegroups.com William Bryant 
gogobe...@gmail.com writes:

 @Jugurtha Hadjar
 What does user_input.lower() mean/do?

String objects have a number of built-in functions, lower() being one of
them.  It returns a copy of the string with all uppercase letters converted
to lowercase.

Example:

 x = Hello There
 y = x.lower()
 print y
hello there

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

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


Re: Help please, why doesn't it show the next input?

2013-09-11 Thread Dave Angel
On 11/9/2013 15:31, William Bryant wrote:

 @Dave Angel

 What is .lower() ?
It is a method on the str class.

You could teach yourself.  At the interpreter prompt, type

 help(test response.lower)

Or on the web:

http://docs.python.org/2/library/stdtypes.html#str.lower

There are lots of other interesting methods in the str class, listed on
that section of that page.

-- 
DaveA


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


RE: Help please, why doesn't it show the next input?

2013-09-11 Thread Prasad, Ramit
William Bryant wrote:
 Sent: Wednesday, September 11, 2013 2:32 PM
 To: python-list@python.org
 Subject: Re: Help please, why doesn't it show the next input?
 
 @Dave Angel
 
 What is .lower() ?

Thanks for bottom posting and trimming, but you should
leave some content quoted for context. Otherwise
people will not what you are referring to.

You can find answers to questions like this in the API.
http://docs.python.org/2/library/stdtypes.html#str.lower

I would recommend taking time to get familiar with the
Athena interpreter. It can also answer questions like
this (but with less detail than the web API).

You can use dir() to find the attributes on any object.
help() will give you docstring for the attribute/class.

 'A'.lower()
'a'
 help(''.lower)
Help on built-in function lower:

lower(...)
S.lower() - string

Return a copy of the string S converted to lowercase.

 help(dir)
Help on built-in function dir in module __builtin__:
dir(...)
dir([object]) - list of strings

If called without an argument, return the names in the current scope.
Else, return an alphabetized list of names comprising (some of) the 
attributes
of the given object, and of attributes reachable from it.
If the object supplies a method named __dir__, it will be used; otherwise
the default dir() logic is used and returns:
  for a module object: the module's attributes.
  for a class object:  its attributes, and recursively the attributes
of its bases.
  for any other object: its attributes, its class's attributes, and

recursively the attributes of its class's base classes.
 dir('')
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', 
'__format__', '__ge__', '__getattribute__', '__getitem_\
_', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', 
'__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__\
', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', 
'__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclass\
hook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 
'center', 'count', 'decode', 'encode', 'endswith', 'expan\
dtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 
'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lo\
wer', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 
'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'starts\
with', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

If you want to see all the relevant information you can use help()
on the class [e.g. help(str)]. I think help(class) will not show
functions that start with _ unless they are python magic dunder 
functions (e.g. __str__).



~Ramit



This email is confidential and subject to important disclaimers and conditions 
including on offers for the purchase or sale of securities, accuracy and 
completeness of information, viruses, confidentiality, legal privilege, and 
legal entity disclaimers, available at 
http://www.jpmorgan.com/pages/disclosures/email.  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help please, why doesn't it show the next input?

2013-09-11 Thread Terry Reedy

On 9/11/2013 3:31 PM, William Bryant wrote:


What is .lower() ?


The Python docs have a pretty good index that includes 'lower() (str 
method)'.  Learn to use it.


If you know that .lower is a str method,
 help(str.lower)
at interactive prompt prints a page. Learn to use help(ob) also.


--
Terry Jan Reedy

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


Re: Help please, why doesn't it show the next input?

2013-09-11 Thread Jugurtha Hadjar

On 09/11/2013 08:33 PM, William Bryant wrote:

@Jugurtha Hadjar
What does user_input.lower() mean/do?



Hello,

As did other people point out, it returns the lower case of a string. 
It's not user_input.lower(), it's any_string.lower()


For example:

Try this on your python prompt

mystring = ThIs Is ThE wAy SoMe StUpId PeOpLe WrItE i DoN't KnOw WhY!
mystring.lower()





--
~Jugurtha Hadjar,
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help please, why doesn't it show the next input?

2013-09-11 Thread Jugurtha Hadjar

On 09/12/2013 02:08 AM, Jugurtha Hadjar wrote:


Try this on your python prompt

mystring = ThIs Is ThE wAy SoMe StUpId PeOpLe WrItE i DoN't KnOw WhY!
mystring.lower()



This should return:

You shouldn't treat people of stupid, but I feel your pain, or let's 
be more realistic:


this is the way some stupid people write i don't know why!


--
~Jugurtha Hadjar,
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help please, why doesn't it show the next input?

2013-09-10 Thread John Gordon
In ef8de6db-5f35-4d07-8306-bcec47b1e...@googlegroups.com William Bryant 
gogobe...@gmail.com writes:

 Hey, I am very new to python, I am 13 years old. I want to be able to make =
 a program the caculates the mean, meadian and mode. When i run the program,=
  an input field pops up and says 'Does your list contain, a number or a str=
 ing?' like I want it to, but when I type in something that is not one of va=
 lid field options: String or string or STRING or s or S or str =
 or Number or number or NUMBER or N or N or int or num, nothin=
 g happens, please tell me what I did wrong. Thanks :D Here is my code:

 #-   Variables that I am using, including the list.  --=
 ---#

 #False means num
 #True means string
 num_or_string =3D 
 amount_numbers =3D []
 List =3D []
 I =3D Does your list contain, a number or a string?

 #-  Functions that I am using.-=
 #
 input(I)

 def NOS():
 if I =3D=3D String or string or STRING or s or S or str:
 pass
 elif I =3D=3D Number or number or NUMBER or N or N or int o=
 r num:
 pass
 else:
 global I
 I =3D You did not enter a valid field, :P Sorry.
 input(I)

First of all, you haven't given us your whole program.  I know this because
while you've defined the NOS function, it isn't actually called anywhere.
You must have left that part out.

Anyway, I think you're doing two things wrong:

1. You aren't capturing the user's input.  The input() function returns
the user's input, but you aren't assigning this to a variable; it's just
being thrown away.  You should call input() like this:

  user_input = input(I)

(Also, it would probably be clearer to use a name like prompt instead
of I.)

2. You aren't using the compound if statement correctly.  You can't
   do this (well, you CAN, but it won't do what you want):

   if a == 1 or 2 or 3:

   You should fully spell out each condition, like this:

   if a == 1 or a == 2 or a == 3:

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

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


Re: Help please, why doesn't it show the next input?

2013-09-10 Thread William Bryant
On Wednesday, September 11, 2013 5:11:23 PM UTC+12, John Gordon wrote:
 In ef8de6db-5f35-4d07-8306-bcec47b1e...@googlegroups.com William Bryant 
 gogobe...@gmail.com writes:
 
 
 
  Hey, I am very new to python, I am 13 years old. I want to be able to make =
 
  a program the caculates the mean, meadian and mode. When i run the program,=
 
   an input field pops up and says 'Does your list contain, a number or a str=
 
  ing?' like I want it to, but when I type in something that is not one of va=
 
  lid field options: String or string or STRING or s or S or str =
 
  or Number or number or NUMBER or N or N or int or num, nothin=
 
  g happens, please tell me what I did wrong. Thanks :D Here is my code:
 
 
 
  #-   Variables that I am using, including the list.  --=
 
  ---#
 
 
 
  #False means num
 
  #True means string
 
  num_or_string =3D 
 
  amount_numbers =3D []
 
  List =3D []
 
  I =3D Does your list contain, a number or a string?
 
 
 
  #-  Functions that I am using.-=
 
  #
 
  input(I)
 
 
 
  def NOS():
 
  if I =3D=3D String or string or STRING or s or S or str:
 
  pass
 
  elif I =3D=3D Number or number or NUMBER or N or N or int o=
 
  r num:
 
  pass
 
  else:
 
  global I
 
  I =3D You did not enter a valid field, :P Sorry.
 
  input(I)
 
 
 
 First of all, you haven't given us your whole program.  I know this because
 
 while you've defined the NOS function, it isn't actually called anywhere.
 
 You must have left that part out.
 
 
 
 Anyway, I think you're doing two things wrong:
 
 
 
 1. You aren't capturing the user's input.  The input() function returns
 
 the user's input, but you aren't assigning this to a variable; it's just
 
 being thrown away.  You should call input() like this:
 
 
 
   user_input = input(I)
 
 
 
 (Also, it would probably be clearer to use a name like prompt instead
 
 of I.)
 
 
 
 2. You aren't using the compound if statement correctly.  You can't
 
do this (well, you CAN, but it won't do what you want):
 
 
 
if a == 1 or 2 or 3:
 
 
 
You should fully spell out each condition, like this:
 
 
 
if a == 1 or a == 2 or a == 3:
 
 
 
 -- 
 
 John Gordon   A is for Amy, who fell down the stairs
 
 gor...@panix.com  B is for Basil, assaulted by bears
 
 -- Edward Gorey, The Gashlycrumb Tinies

Thanks so much for putting your time into helping me!! It worked! Could you 
tell me if I did anything wrong this time? :)

#-   Variables that I am using, including the list.  -#

num_or_string = 
amount_numbers = []
List = []
prompt = Does your list contain, a number or a string?

#-  Functions that I am using.-#
user_input1 = input(prompt)
user_input1

def NOS():
if user_input1 == String or user_input1 == string or user_input1 == 
STRING or user_input1 == s or user_input1 == S or user_input1 == str:
print(a)
elif user_input1 == Number or user_input1 == number or user_input1 == 
NUMBER or user_input1 == N or user_input1 == N or user_input1 == int or 
user_input1 == num:
print(a)
else:
global user_input2
global prompt
prompt = You did not enter a valid field, :P Sorry.
user_input2 = input(prompt)
user_input2
NOS2()

def NOS2():
if user_input2 == String or user_input2 == string or user_input2 == 
STRING or user_input2 == s or user_input2 == S or user_input2 == str:
print(a)
elif user_input2 == Number or user_input2 == number or user_input2 == 
NUMBER or user_input2 == N or user_input2 == N or user_input2 == int or 
user_input2 == num:
print(a)
else:
global user_input2
global prompt
prompt = You did not enter a valid field, :P Sorry.
user_input2 = input(prompt)
user_input2
NOS2()


NOS()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help please

2013-04-01 Thread Steven D'Aprano
On Sun, 31 Mar 2013 22:41:32 -0700, khaosyt wrote:

 On Monday, April 1, 2013 1:24:52 AM UTC-4, Chris Angelico wrote:
 On Mon, Apr 1, 2013 at 4:15 PM,  khao...@gmail.com wrote:
 
  integer = input(Enter a positive integer: )
 
  again = raw_input(Again? (Y/N): )
 
 
 
 Okay, the first thing I'm going to say is: Don't use input() in Python
 
 2. It's dangerous in ways you won't realize. Use int(raw_input(...))

[...]

 Elaborate, please.


The input() function takes the user's text, and automatically evaluates 
it as if it were code. In the hands of a non-expert, that can lead to 
some unexpected errors:

py answer = input(what is your name? )
what is your name? Steve
Traceback (most recent call last):
  File stdin, line 1, in module
  File string, line 1, in module
NameError: name 'Steve' is not defined



But at least that gives you an error. It can also give you weird and 
unexpected results. Suppose my name was Lenny, and I did this:

py answer = input(what is your name? )
what is your name? len
py print answer
built-in function len



Worse, because input evaluates text as code, it can do anything, 
including bad things:

py answer = input(what is your name? )
what is your name? 200**300**300
Traceback (most recent call last):
  File stdin, line 1, in module
  File string, line 1, in module
MemoryError


(while the above code was running, my computer got slower and slower and 
slower, and potentially it could have locked up completely).


So the general advice is, treat the input() function as For Experts Only, 
and always use raw_input() instead.




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


Re: Help please

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 4:15 PM,  khao...@gmail.com wrote:
 integer = input(Enter a positive integer: )
 again = raw_input(Again? (Y/N): )

Okay, the first thing I'm going to say is: Don't use input() in Python
2. It's dangerous in ways you won't realize. Use int(raw_input(...))
for something like this, which will guarantee you an integer.

I'm guessing this is homework. Please be honest about that; we'll help
you learn but won't just give you the answers.

All you need to do is initialize something to zero, and then keep
adding 'number' onto it in the loop. You should be able to sort that
out.

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


Re: Help please

2013-03-31 Thread khaosyt
On Monday, April 1, 2013 1:24:52 AM UTC-4, Chris Angelico wrote:
 On Mon, Apr 1, 2013 at 4:15 PM,  khao...@gmail.com wrote:
 
  integer = input(Enter a positive integer: )
 
  again = raw_input(Again? (Y/N): )
 
 
 
 Okay, the first thing I'm going to say is: Don't use input() in Python
 
 2. It's dangerous in ways you won't realize. Use int(raw_input(...))
 
 for something like this, which will guarantee you an integer.
 
 
 
 I'm guessing this is homework. Please be honest about that; we'll help
 
 you learn but won't just give you the answers.
 
 
 
 All you need to do is initialize something to zero, and then keep
 
 adding 'number' onto it in the loop. You should be able to sort that
 
 out.
 
 
 
 ChrisA

Elaborate, please.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help please! strange Tkinter behavior has me totally baffled.

2010-08-25 Thread Steve Ferg
Thanks mucho!  That was it!
-- Steve Ferg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help please! strange Tkinter behavior has me totally baffled.

2010-08-24 Thread Peter Otten
Steve Ferg wrote:

 I have a short Python script that uses Tkinter to display an image.
 Here is the script
 
 ===
 import sys, os
 from   Tkinter import *
 root = Tk()  # A: create a global variable named root
 
 def showPicture(imageFilename):
 # global root   #C: make root global
 root = Tk()  # B: create a local variable named root
 
 imageFrame = Frame(root)
 imageFrame.pack()
 
 imageObject = PhotoImage(file=imageFilename)
 
 label = Label(imageFrame,image=imageObject)
 label.pack()
 
 root.mainloop()
 
 showPicture(python_and_check_logo.gif)
 ===
 
 The strange thing is that it crashes with this traceback...
 
 ===
 
 Traceback (most recent call last):
   File easygui_test3.py, line 19, in module
 showPicture(python_and_check_logo.gif)
   File easygui_test3.py, line 14, in showPicture
 label = Label(imageFrame,image=imageObject)
   File L:\FergLabstatPublic\Python26\lib\lib-tk\Tkinter.py, line
 2474, in __init__
 Widget.__init__(self, master, 'label', cnf, kw)
   File L:\FergLabstatPublic\Python26\lib\lib-tk\Tkinter.py, line
 1940, in __init__
 (widgetName, self._w) + extra + self._options(cnf))
 _tkinter.TclError: image pyimage1 doesn't exist
 
 ===
 
 If I comment out either line A or line B, the script works fine.
 
 What I don't understand is why creating a global root variable and a
 local root variable causes the script to crash.
 
 Even more puzzling... if I uncomment line C, so that root in line B
 refers to a global root variable, the script still crashes.
 
 I'm totally baffled.  Does anybody know what is going on here?
 
 -- Steve Ferg
 (I'm running Python 2.6 under Windows, but  I get the same behavior
 under Solaris.)

Tkinter.Tk() creates a new Tcl interpreter. Are you sure you want that? The 
standard way to create an additional window is Tkinter.Toplevel().

The PhotoImage is created in the default (first) interpreter and then looked 
up in the Label's (second) interpreter. At least that's what I would infer 
from

class Image:
Base class for images.
_last_id = 0
def __init__(self, imgtype, name=None, cnf={}, master=None, **kw):
self.name = None
if not master:
master = _default_root
if not master:
raise RuntimeError, 'Too early to create image'
self.tk = master.tk

in the Tkinter source which also makes it plausible that you can avoid the 
problem by specifying an explicit master

def showPicture(imageFilename):
root = Tk()
# ...
imageObject = PhotoImage(file=imageFilename, master=root)
# ...

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help Please

2009-08-21 Thread Albert Hopkins
Why do you post the same question twice within 5 minutes of each other?


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


Re: help please, splitter windows like in maya or 3ds max

2008-03-13 Thread moonrie
On Mar 13, 12:47 pm, Andrew Rekdal nospam@comcast.net wrote:
 This seems to work... split then split each side. then tandem the size.

 import wx

 class Layout(wx.Frame):

 def __init__(self, parent, id, title):

 wx.Frame.__init__(self, parent, id, title)

 sizer = wx.BoxSizer(wx.HORIZONTAL)

 panel = wx.Panel(self,-1)

 splitter = wx.SplitterWindow(panel)

 sizer_left = wx.BoxSizer(wx.VERTICAL)

 panel_left = wx.Panel(splitter,-1)

 splitter_left = wx.SplitterWindow(panel_left)

 splitter_left.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,self.leftChange,id=splitter_left.GetId())

 panel_left_upper = wx.Panel(splitter_left,style= wx.BORDER_SUNKEN)

 panel_left_upper.SetBackgroundColour(WHITE)

 panel_left_lower = wx.Panel(splitter_left,style= wx.BORDER_SUNKEN)

 splitter_left.SplitHorizontally(panel_left_upper,panel_left_lower)

 sizer_left.Add(splitter_left,1,wx.EXPAND)

 sizer_right = wx.BoxSizer(wx.VERTICAL)

 panel_right = wx.Panel(splitter,-1)

 splitter_right =wx.SplitterWindow(panel_right)

 splitter_right.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,self.rightChange,id=splitter_right.GetId())

 panel_right_upper = wx.Panel(splitter_right,style= wx.BORDER_SUNKEN)

 panel_right_lower = wx.Panel(splitter_right,style= wx.BORDER_SUNKEN)

 panel_right_lower.SetBackgroundColour(WHITE)

 splitter_right.SplitHorizontally(panel_right_upper,panel_right_lower)

 sizer_right.Add(splitter_right,1,wx.EXPAND)

 splitter.SplitVertically(panel_left,panel_right)

 sizer.Add(splitter,1,wx.EXPAND)

 panel.SetSizer(sizer)

 panel_left.SetSizer(sizer_left)

 panel_right.SetSizer(sizer_right)

 self.splitter_left = splitter_left

 self.splitter_right = splitter_right

 def leftChange(self,event):

 pos = self.splitter_left.GetSashPosition()

 self.splitter_right.SetSashPosition(pos)

 event.Skip()

 def rightChange(self,event):

 pos = self.splitter_right.GetSashPosition()

 self.splitter_left.SetSashPosition(pos)

 event.Skip()

 app = wx.App(0)

 k = Layout(None, -1, 'layout.py')

 k.Show(True)

 app.MainLoop()

 -- Andrew

 - Original Message -
 From: moonrie [EMAIL PROTECTED]

 Newsgroups: comp.lang.python
 Sent: Wednesday, March 12, 2008 10:19 PM
 Subject: help please, splitter windows like in maya or 3ds max

  hi, everyone there, I am doing a 3D modeling project. I like to do it
  with Python( am a newbie), but have no idea with the wxSplitterWindow
  to create the 4-view windows( top, front, side, perspective), like the
  mfc CSplitterWnd guy),
  anyone can give me some help with wxPython?

  thanks in advance.

  - moonrie

should be these ones,

thanks, :P
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help please, splitter windows like in maya or 3ds max

2008-03-13 Thread John at Quintivity
Sounds like this might do exactly what you need...
http://xoomer.alice.it/infinity77/main/FourWaySplitter.html

Cheers,
John



On Thu, Mar 13, 2008 at 1:45 AM, moonrie [EMAIL PROTECTED] wrote:

 On Mar 13, 12:47 pm, Andrew Rekdal nospam@comcast.net wrote:
  This seems to work... split then split each side. then tandem the size.
 
  import wx
 
  class Layout(wx.Frame):
 
  def __init__(self, parent, id, title):
 
  wx.Frame.__init__(self, parent, id, title)
 
  sizer = wx.BoxSizer(wx.HORIZONTAL)
 
  panel = wx.Panel(self,-1)
 
  splitter = wx.SplitterWindow(panel)
 
  sizer_left = wx.BoxSizer(wx.VERTICAL)
 
  panel_left = wx.Panel(splitter,-1)
 
  splitter_left = wx.SplitterWindow(panel_left)
 
  splitter_left.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,self.leftChange
 ,id=splitter_left.GetId())
 
  panel_left_upper = wx.Panel(splitter_left,style= wx.BORDER_SUNKEN)
 
  panel_left_upper.SetBackgroundColour(WHITE)
 
  panel_left_lower = wx.Panel(splitter_left,style= wx.BORDER_SUNKEN)
 
  splitter_left.SplitHorizontally(panel_left_upper,panel_left_lower)
 
  sizer_left.Add(splitter_left,1,wx.EXPAND)
 
  sizer_right = wx.BoxSizer(wx.VERTICAL)
 
  panel_right = wx.Panel(splitter,-1)
 
  splitter_right =wx.SplitterWindow(panel_right)
 
  splitter_right.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,self.rightChange
 ,id=splitter_right.GetId())
 
  panel_right_upper = wx.Panel(splitter_right,style= wx.BORDER_SUNKEN)
 
  panel_right_lower = wx.Panel(splitter_right,style= wx.BORDER_SUNKEN)
 
  panel_right_lower.SetBackgroundColour(WHITE)
 
  splitter_right.SplitHorizontally(panel_right_upper,panel_right_lower)
 
  sizer_right.Add(splitter_right,1,wx.EXPAND)
 
  splitter.SplitVertically(panel_left,panel_right)
 
  sizer.Add(splitter,1,wx.EXPAND)
 
  panel.SetSizer(sizer)
 
  panel_left.SetSizer(sizer_left)
 
  panel_right.SetSizer(sizer_right)
 
  self.splitter_left = splitter_left
 
  self.splitter_right = splitter_right
 
  def leftChange(self,event):
 
  pos = self.splitter_left.GetSashPosition()
 
  self.splitter_right.SetSashPosition(pos)
 
  event.Skip()
 
  def rightChange(self,event):
 
  pos = self.splitter_right.GetSashPosition()
 
  self.splitter_left.SetSashPosition(pos)
 
  event.Skip()
 
  app = wx.App(0)
 
  k = Layout(None, -1, 'layout.py')
 
  k.Show(True)
 
  app.MainLoop()
 
  -- Andrew
 
  - Original Message -
  From: moonrie [EMAIL PROTECTED]
 
  Newsgroups: comp.lang.python
  Sent: Wednesday, March 12, 2008 10:19 PM
  Subject: help please, splitter windows like in maya or 3ds max
 
   hi, everyone there, I am doing a 3D modeling project. I like to do it
   with Python( am a newbie), but have no idea with the wxSplitterWindow
   to create the 4-view windows( top, front, side, perspective), like the
   mfc CSplitterWnd guy),
   anyone can give me some help with wxPython?
 
   thanks in advance.
 
   - moonrie

 should be these ones,

 thanks, :P
 --
 http://mail.python.org/mailman/listinfo/python-list

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

Re: help please, splitter windows like in maya or 3ds max

2008-03-12 Thread Andrew Rekdal
This seems to work... split then split each side. then tandem the size.

import wx


class Layout(wx.Frame):




def __init__(self, parent, id, title):

wx.Frame.__init__(self, parent, id, title)

sizer = wx.BoxSizer(wx.HORIZONTAL)

panel = wx.Panel(self,-1)


splitter = wx.SplitterWindow(panel)


sizer_left = wx.BoxSizer(wx.VERTICAL)

panel_left = wx.Panel(splitter,-1)

splitter_left = wx.SplitterWindow(panel_left)

splitter_left.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,self.leftChange,id=splitter_left.GetId())


panel_left_upper = wx.Panel(splitter_left,style= wx.BORDER_SUNKEN)


panel_left_upper.SetBackgroundColour(WHITE)

panel_left_lower = wx.Panel(splitter_left,style= wx.BORDER_SUNKEN)

splitter_left.SplitHorizontally(panel_left_upper,panel_left_lower)

sizer_left.Add(splitter_left,1,wx.EXPAND)


sizer_right = wx.BoxSizer(wx.VERTICAL)

panel_right = wx.Panel(splitter,-1)

splitter_right =wx.SplitterWindow(panel_right)

splitter_right.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,self.rightChange,id=splitter_right.GetId())

panel_right_upper = wx.Panel(splitter_right,style= wx.BORDER_SUNKEN)

panel_right_lower = wx.Panel(splitter_right,style= wx.BORDER_SUNKEN)

panel_right_lower.SetBackgroundColour(WHITE)

splitter_right.SplitHorizontally(panel_right_upper,panel_right_lower)

sizer_right.Add(splitter_right,1,wx.EXPAND)


splitter.SplitVertically(panel_left,panel_right)


sizer.Add(splitter,1,wx.EXPAND)


panel.SetSizer(sizer)

panel_left.SetSizer(sizer_left)

panel_right.SetSizer(sizer_right)

self.splitter_left = splitter_left

self.splitter_right = splitter_right

def leftChange(self,event):


pos = self.splitter_left.GetSashPosition()

self.splitter_right.SetSashPosition(pos)

event.Skip()

def rightChange(self,event):


pos = self.splitter_right.GetSashPosition()

self.splitter_left.SetSashPosition(pos)

event.Skip()


app = wx.App(0)

k = Layout(None, -1, 'layout.py')

k.Show(True)


app.MainLoop()

-- Andrew

- Original Message - 
From: moonrie [EMAIL PROTECTED]
Newsgroups: comp.lang.python
Sent: Wednesday, March 12, 2008 10:19 PM
Subject: help please, splitter windows like in maya or 3ds max


 hi, everyone there, I am doing a 3D modeling project. I like to do it
 with Python( am a newbie), but have no idea with the wxSplitterWindow
 to create the 4-view windows( top, front, side, perspective), like the
 mfc CSplitterWnd guy),
 anyone can give me some help with wxPython?

 thanks in advance.

 - moonrie 


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


Re: Help please with code to find and move files.

2007-12-31 Thread Gabriel Genellina
En Mon, 31 Dec 2007 05:09:37 -0200, [EMAIL PROTECTED] escribió:

 I am sorry if I was not clear in what I was trying to achieve. All I
 wanted was simple way to achieve what windows does when you use search
 for Files or Folders,  and all the files that mach two words like foo
 and bar in the file name to be moved or copied to a specified folder,
 duplicates should not be copied just skipped.

I think John Machim comments addressed most -if not all- your potential  
problems. You should be able to modify your script to met your goals; just  
do it one step at a time. Omit the actual file copy at first, just print  
what you would do. See what happens, fix the iteration if needed, once you  
print the right set of files try to actually copy them.

-- 
Gabriel Genellina

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


Re: Help please with code to find and move files.

2007-12-30 Thread infixum

 path = rc:\\

I don't know if this is the whole problem, but this line should read
r'c:\' (one backslash).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help please with code to find and move files.

2007-12-30 Thread inFocus
On Sun, 30 Dec 2007 18:42:50 -0800 (PST), infixum [EMAIL PROTECTED]
wrote:


 path = rc:\\

I don't know if this is the whole problem, but this line should read
r'c:\' (one backslash).


after changing i got this

path = rc:\
^
SyntaxError: EOL while scanning single-quoted string

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


Re: Help please with code to find and move files.

2007-12-30 Thread infixum


 after changing i got this

     path = rc:\
                 ^
 SyntaxError: EOL while scanning single-quoted string

Sorry about that.  You can't end with a backslash - my bad.  I just
tried this in the interpreter and 'c:' works.

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


Re: Help please with code to find and move files.

2007-12-30 Thread John Machin
On Dec 31, 1:04 pm, [EMAIL PROTECTED] wrote:
 Hello,

 I am new to python and wanted to write something for myself where
 after inputing two words it would search entire drive and when finding
 both names in files name would either copy or move thoe files to a
 specified directory.

 But couple of attempts did not work as desired this is one of them.

Care to provide some more details than did not work as desired? Do
you think the problem is in the finding or in the copying? I've given
some comments below, but you really need to think through what as
desired means ...

Suppose your search words are foo and bar, that C:\files is an
empty folder, and the following 3 files exist:
C:\a\foobar.txt
C:\b\foobar.txt
C:\b\barfoo.txt

What do you want to happen the first time you run the script? ... if
you run it a second time? If it's your intention not to make a copy of
C:\b\foobar.txt (because its basename is the same as that of C:\a
\foobar.txt), consider the desirability of warning yourself when this
situation happens.

 Could someone help fix it or maybe give a better example.

  Thank you very much.

 import os, os.path, shutil

 path = rc:\\

Leave out the r; you are getting TWO backslashes:

 path = rc:\\
 len(path)
4
 import os
 wkr = os.walk('rd:\\')
 wkr.next()
Traceback (most recent call last):
  File stdin, line 1, in module
StopIteration
# Nothing inside your for statement would be executed
 wkr = os.walk('d:\\')
 wkr.next()
('d:\\', a list of folders, a list of files)


 dest_file = 'C:\\files'

Presumably that would be better named dest_dir ...

 name_search = raw_input('Please enter name searchs : ').split()
 dup = []

In the (unlikely) event that an in-memory structure with no knowledge
of what happened on previous runs will do what you really want to do,
then consider a set instead of a list.


 for root, dirs, files in os.walk(path):
     for name in files:
                 file_name = os.path.join(root, name)
                 if (name_search[0] in file_name) and (name_search[1]
 in file_name):
                         #if os.path.join(root, name) in dest_file:
                         if file_name in dup:

What do you really intend to do here? dup contains the FULL PATH of
each file that you have found; if you come across another instance of
one of those, either os.walk is horribly broken or your filesystem has
a loop in its directory structure.

If you really mean am I about to try to copy over the top of an
existing file, attack the problem head-on: make the full path of the
file you are about to try to create, and use os.path.exists on it.

                                 break

Why break?

You also want to avoid trying to copy files in the backup
(dest_file) directory, perhaps including ones that you have just
copied there. Try a simple test
if root == dest_file:
continue
very early in your outer loop. It's probably a good idea to wrap
os.path.abspath() around root and destfile.

                         else:
                                 print copied %s to %s % (name,
 dest_file)
                                 shutil.copy(os.path.join(root, name),
 dest_file)

You may prefer the results of copy2 to those of copy.

                                 dup.append(file_name)

HTH,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help please with code to find and move files.

2007-12-30 Thread inFocus
On Sun, 30 Dec 2007 19:29:38 -0800 (PST), John Machin
[EMAIL PROTECTED] wrote:

On Dec 31, 1:04 pm, [EMAIL PROTECTED] wrote:
 Hello,

 I am new to python and wanted to write something for myself where
 after inputing two words it would search entire drive and when finding
 both names in files name would either copy or move thoe files to a
 specified directory.

 But couple of attempts did not work as desired this is one of them.

Care to provide some more details than did not work as desired? Do
you think the problem is in the finding or in the copying? I've given
some comments below, but you really need to think through what as
desired means ...

Suppose your search words are foo and bar, that C:\files is an
empty folder, and the following 3 files exist:
C:\a\foobar.txt
C:\b\foobar.txt
C:\b\barfoo.txt

What do you want to happen the first time you run the script? ... if
you run it a second time? If it's your intention not to make a copy of
C:\b\foobar.txt (because its basename is the same as that of C:\a
\foobar.txt), consider the desirability of warning yourself when this
situation happens.

 Could someone help fix it or maybe give a better example.

  Thank you very much.

 import os, os.path, shutil

 path = rc:\\

Leave out the r; you are getting TWO backslashes:

 path = rc:\\
 len(path)
4
 import os
 wkr = os.walk('rd:\\')
 wkr.next()
Traceback (most recent call last):
  File stdin, line 1, in module
StopIteration
# Nothing inside your for statement would be executed
 wkr = os.walk('d:\\')
 wkr.next()
('d:\\', a list of folders, a list of files)


 dest_file = 'C:\\files'

Presumably that would be better named dest_dir ...

 name_search = raw_input('Please enter name searchs : ').split()
 dup = []

In the (unlikely) event that an in-memory structure with no knowledge
of what happened on previous runs will do what you really want to do,
then consider a set instead of a list.


 for root, dirs, files in os.walk(path):
     for name in files:
                 file_name = os.path.join(root, name)
                 if (name_search[0] in file_name) and (name_search[1]
 in file_name):
                         #if os.path.join(root, name) in dest_file:
                         if file_name in dup:

What do you really intend to do here? dup contains the FULL PATH of
each file that you have found; if you come across another instance of
one of those, either os.walk is horribly broken or your filesystem has
a loop in its directory structure.

If you really mean am I about to try to copy over the top of an
existing file, attack the problem head-on: make the full path of the
file you are about to try to create, and use os.path.exists on it.

                                 break

Why break?

You also want to avoid trying to copy files in the backup
(dest_file) directory, perhaps including ones that you have just
copied there. Try a simple test
if root == dest_file:
continue
very early in your outer loop. It's probably a good idea to wrap
os.path.abspath() around root and destfile.

                         else:
                                 print copied %s to %s % (name,
 dest_file)
                                 shutil.copy(os.path.join(root, name),
 dest_file)

You may prefer the results of copy2 to those of copy.

                                 dup.append(file_name)

HTH,
John

John,

What I was trying to do is find files that are scattered all over my
hard drive that contain similar two words in them like bar and foo 
and move them to one desired location removing from where they were
originally.  The did not work as desired were attempts when it would
attempt to read and write to the same location.so i would get an error
saying that source and destination were  the same.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help please with code to find and move files.

2007-12-30 Thread John Machin
On Dec 31, 2:44 pm, [EMAIL PROTECTED] wrote:
 On Sun, 30 Dec 2007 19:29:38 -0800 (PST), John Machin





 [EMAIL PROTECTED] wrote:
 On Dec 31, 1:04 pm, [EMAIL PROTECTED] wrote:
  Hello,

  I am new to python and wanted to write something for myself where
  after inputing two words it would search entire drive and when finding
  both names in files name would either copy or move thoe files to a
  specified directory.

  But couple of attempts did not work as desired this is one of them.

 Care to provide some more details than did not work as desired? Do
 you think the problem is in the finding or in the copying? I've given
 some comments below, but you really need to think through what as
 desired means ...

 Suppose your search words are foo and bar, that C:\files is an
 empty folder, and the following 3 files exist:
 C:\a\foobar.txt
 C:\b\foobar.txt
 C:\b\barfoo.txt

 What do you want to happen the first time you run the script? ... if
 you run it a second time? If it's your intention not to make a copy of
 C:\b\foobar.txt (because its basename is the same as that of C:\a
 \foobar.txt), consider the desirability of warning yourself when this
 situation happens.

  Could someone help fix it or maybe give a better example.

   Thank you very much.

  import os, os.path, shutil

  path = rc:\\

 Leave out the r; you are getting TWO backslashes:

  path = rc:\\
  len(path)
 4
  import os
  wkr = os.walk('rd:\\')
  wkr.next()
 Traceback (most recent call last):
   File stdin, line 1, in module
 StopIteration
 # Nothing inside your for statement would be executed
  wkr = os.walk('d:\\')
  wkr.next()
 ('d:\\', a list of folders, a list of files)

  dest_file = 'C:\\files'

 Presumably that would be better named dest_dir ...

  name_search = raw_input('Please enter name searchs : ').split()
  dup = []

 In the (unlikely) event that an in-memory structure with no knowledge
 of what happened on previous runs will do what you really want to do,
 then consider a set instead of a list.

  for root, dirs, files in os.walk(path):
      for name in files:
                  file_name = os.path.join(root, name)
                  if (name_search[0] in file_name) and (name_search[1]
  in file_name):
                          #if os.path.join(root, name) in dest_file:
                          if file_name in dup:

 What do you really intend to do here? dup contains the FULL PATH of
 each file that you have found; if you come across another instance of
 one of those, either os.walk is horribly broken or your filesystem has
 a loop in its directory structure.

 If you really mean am I about to try to copy over the top of an
 existing file, attack the problem head-on: make the full path of the
 file you are about to try to create, and use os.path.exists on it.

                                  break

 Why break?

 You also want to avoid trying to copy files in the backup
 (dest_file) directory, perhaps including ones that you have just
 copied there. Try a simple test
     if root == dest_file:
         continue
 very early in your outer loop. It's probably a good idea to wrap
 os.path.abspath() around root and destfile.

                          else:
                                  print copied %s to %s % (name,
  dest_file)
                                  shutil.copy(os.path.join(root, name),
  dest_file)

 You may prefer the results of copy2 to those of copy.

                                  dup.append(file_name)

 HTH,
 John

 John,

 What I was trying to do is find files that are scattered all over my
 hard drive that contain similar two words in them like bar and foo
 and move them to one desired location removing from where they were
 originally.  The did not work as desired were attempts when it would
 attempt to read and write to the same location.so i would get an error
 saying that source and destination were  the same.- Hide quoted text -

 - Show quoted text -

The script that you showed would not have found any files to move/
copy, as infixum and I have pointed out.

Imagine that you were trying to help someone with a Python problem ...
would you not like them to tell you (with some precision) what they
were trying to do, what was the script that they actually ran, what
the precise result (including stack trace and error message if any)
was? Or do you like playing guessing games?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help please with code to find and move files.

2007-12-30 Thread inFocus
On Sun, 30 Dec 2007 20:49:29 -0800 (PST), John Machin
[EMAIL PROTECTED] wrote:

On Dec 31, 2:44 pm, [EMAIL PROTECTED] wrote:
 On Sun, 30 Dec 2007 19:29:38 -0800 (PST), John Machin





 [EMAIL PROTECTED] wrote:
 On Dec 31, 1:04 pm, [EMAIL PROTECTED] wrote:
  Hello,

  I am new to python and wanted to write something for myself where
  after inputing two words it would search entire drive and when finding
  both names in files name would either copy or move thoe files to a
  specified directory.

  But couple of attempts did not work as desired this is one of them.

 Care to provide some more details than did not work as desired? Do
 you think the problem is in the finding or in the copying? I've given
 some comments below, but you really need to think through what as
 desired means ...

 Suppose your search words are foo and bar, that C:\files is an
 empty folder, and the following 3 files exist:
 C:\a\foobar.txt
 C:\b\foobar.txt
 C:\b\barfoo.txt

 What do you want to happen the first time you run the script? ... if
 you run it a second time? If it's your intention not to make a copy of
 C:\b\foobar.txt (because its basename is the same as that of C:\a
 \foobar.txt), consider the desirability of warning yourself when this
 situation happens.

  Could someone help fix it or maybe give a better example.

   Thank you very much.

  import os, os.path, shutil

  path = rc:\\

 Leave out the r; you are getting TWO backslashes:

  path = rc:\\
  len(path)
 4
  import os
  wkr = os.walk('rd:\\')
  wkr.next()
 Traceback (most recent call last):
   File stdin, line 1, in module
 StopIteration
 # Nothing inside your for statement would be executed
  wkr = os.walk('d:\\')
  wkr.next()
 ('d:\\', a list of folders, a list of files)

  dest_file = 'C:\\files'

 Presumably that would be better named dest_dir ...

  name_search = raw_input('Please enter name searchs : ').split()
  dup = []

 In the (unlikely) event that an in-memory structure with no knowledge
 of what happened on previous runs will do what you really want to do,
 then consider a set instead of a list.

  for root, dirs, files in os.walk(path):
      for name in files:
                  file_name = os.path.join(root, name)
                  if (name_search[0] in file_name) and (name_search[1]
  in file_name):
                          #if os.path.join(root, name) in dest_file:
                          if file_name in dup:

 What do you really intend to do here? dup contains the FULL PATH of
 each file that you have found; if you come across another instance of
 one of those, either os.walk is horribly broken or your filesystem has
 a loop in its directory structure.

 If you really mean am I about to try to copy over the top of an
 existing file, attack the problem head-on: make the full path of the
 file you are about to try to create, and use os.path.exists on it.

                                  break

 Why break?

 You also want to avoid trying to copy files in the backup
 (dest_file) directory, perhaps including ones that you have just
 copied there. Try a simple test
     if root == dest_file:
         continue
 very early in your outer loop. It's probably a good idea to wrap
 os.path.abspath() around root and destfile.

                          else:
                                  print copied %s to %s % (name,
  dest_file)
                                  shutil.copy(os.path.join(root, name),
  dest_file)

 You may prefer the results of copy2 to those of copy.

                                  dup.append(file_name)

 HTH,
 John

 John,

 What I was trying to do is find files that are scattered all over my
 hard drive that contain similar two words in them like bar and foo
 and move them to one desired location removing from where they were
 originally.  The did not work as desired were attempts when it would
 attempt to read and write to the same location.so i would get an error
 saying that source and destination were  the same.- Hide quoted text -

 - Show quoted text -

The script that you showed would not have found any files to move/
copy, as infixum and I have pointed out.

Imagine that you were trying to help someone with a Python problem ...
would you not like them to tell you (with some precision) what they
were trying to do, what was the script that they actually ran, what
the precise result (including stack trace and error message if any)
was? Or do you like playing guessing games?


I am sorry i thought I did say what I was tryng to do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help please with code to find and move files.

2007-12-30 Thread inFocus
On Sun, 30 Dec 2007 22:52:32 -0800, Dennis Lee Bieber
[EMAIL PROTECTED] wrote:

On Sun, 30 Dec 2007 23:58:17 -0500, [EMAIL PROTECTED] declaimed the
following in comp.lang.python:


 I am sorry i thought I did say what I was tryng to do.

   The only thing I picked up from the thread is that you attempted to
move any file, whose name contained -- in any order/position -- two
specific substrings, from some specified source directory tree to a
single specified directory.

   Among the unknowns: what happens if two source directories have
files with identical names! Does the second overwrite the first? Does
the second NOT get moved? Should the second have the name modified with
a suffix count?

   a/something.wht -  dest/something.wht
   b/something.wht -  ?
   1) 
 replace the first something.wht
   
 (thereby losing a/something.wht)
   2) 
 don't move -- leaving 
   
 b/something.wht unmoved
   3) 
 rename as
   
 dest/something1.wht

   Neither do I have any idea of what type of problem you really
encountered (you'll have to forgive me, but I do not intend to try
running your script, on my system, given that I do not know what the
effects, in the end, are to be).

   The closest to what you seem to ask, that I've created in the past,
is a task to identify potential duplicate files (I have a large number
of downloaded images). Note the date -- I think it predated os.walk()

-=-=-=-=-=-=-
#
#  DupCheck.py --  Scans a directory and all subdirectories
#  for duplicate file names, reporting conflicts
#  March 22 1998   dl bieber [EMAIL PROTECTED]
#

import os
import sys
import string
from stat import *

Files = {}

def Scan_Dir(cd):
   global Files, logfile

   cur_files = os.listdir(cd)
   cur_files.sort()
   for f in cur_files:
   fib = os.stat(%s\\%s % (cd, f))
   if S_ISDIR(fib[ST_MODE]):
   Scan_Dir(%s\\%s % (cd, f))
   elif S_ISREG(fib[ST_MODE]):
   if Files.has_key(string.lower(f)):
   (aSize, aDir) = Files[string.lower(f)]
   if fib[ST_SIZE] == aSize:
   logfile.write(
   *  Possible Duplicate 
 File: %s\n % (f))
   logfile.write(
  %s\t%s\n % 
 (fib[ST_SIZE], cd))
   logfile.write(
  %s\t%s\n\n % 
 (Files[string.lower(f)]))
   else:
   Files[string.lower(f)] = (fib[ST_SIZE], cd)
   else:
   logfile.write(
   *  SKIPPED  Not File or Dir: %s\n\n % (f))


if __name__ == __main__:
   Cur_Dir = raw_input(Root Directory - )
   Log_To = raw_input(Log File - )

   if Log_To:
   logfile = open(Log_To, w)
   else:
   logfile = sys.stdout

   Scan_Dir(Cur_Dir)

   if Log_To:
   logfile.close()
-=-=-=-=-=-

I am sorry if I was not clear in what I was trying to achieve. All I
wanted was simple way to achieve what windows does when you use search
for Files or Folders,  and all the files that mach two words like foo
and bar in the file name to be moved or copied to a specified folder,
duplicates should not be copied just skipped.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help Please - Need to make SOAPpy server multithreaded or handle problem some other way

2007-12-13 Thread sberry
On Dec 13, 12:38 pm, sberry [EMAIL PROTECTED] wrote:
 I have a SOAP server running using SOAPpy.  The problem I am having is
 that it only handles a single request at a time.  It needs to be able
 to accept as many simultaneous requests as come in.

 What is the best way to achieve this?  I really appreciate any help
 here.

Found the answer.  Started reading the Server.py file to make updates
required and found a ThreadingSOAPServer... now it all just works.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help please!!

2007-02-11 Thread hg
darren112 wrote:

 Hi Im new to python and I desperately need help with this task
 This is everything of what I need to do...
 
 The program to be written in Python obviously..
 
 The program should support brute-forcing of the authentication process
 for a Telnet server via a dictionary attack.
 
 The python program is required to take four parameters: a) the IP
 address of a Computer, b) the port number that the Telnet server is
 running on the computer , c) the name of a file containing a list if
 usernames, and b) the name of a file containing a list of word/phrases
 to be used as passwords.
 
 The program should then attempt to authenticate itself to the Telnet
 server via trying every password for every username. The program
 should report when it is successful.
 
 Please help me And as I am new to all this please post step by
 step instructions...

That is funny !

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


Re: help please!!

2007-02-11 Thread azrael
well, this sounds funn.

1) dont expect someone to do your homework.
2) dont expect someone to do dirty homework
3) dont expect someone to do your home work especially when it's
something that could make you problems, or the person that is helping
you
4) from your message i can read that you need the application, and
not some knowledge. I don't know what other guys here think about it,
if my opinion can considered, you are on your own.

i suggest you take a python tutorial and learn how to do it yourself.
This situation stinks.






On Feb 11, 8:40 pm, darren112 [EMAIL PROTECTED] wrote:
 Hi Im new to python and I desperately need help with this task
 This is everything of what I need to do...

 The program to be written in Python obviously..

 The program should support brute-forcing of the authentication process
 for a Telnet server via a dictionary attack.

 The python program is required to take four parameters: a) the IP
 address of a Computer, b) the port number that the Telnet server is
 running on the computer , c) the name of a file containing a list if
 usernames, and b) the name of a file containing a list of word/phrases
 to be used as passwords.

 The program should then attempt to authenticate itself to the Telnet
 server via trying every password for every username. The program
 should report when it is successful.

 Please help me And as I am new to all this please post step by
 step instructions...


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


Re: help please!!

2007-02-11 Thread Jonathan Curran
On Sunday 11 February 2007 13:40, darren112 wrote:
 Hi Im new to python and I desperately need help with this task
 This is everything of what I need to do...

 The program to be written in Python obviously..

 The program should support brute-forcing of the authentication process
 for a Telnet server via a dictionary attack.

 The python program is required to take four parameters: a) the IP
 address of a Computer, b) the port number that the Telnet server is
 running on the computer , c) the name of a file containing a list if
 usernames, and b) the name of a file containing a list of word/phrases
 to be used as passwords.

 The program should then attempt to authenticate itself to the Telnet
 server via trying every password for every username. The program
 should report when it is successful.

 Please help me And as I am new to all this please post step by
 step instructions...

/me points and laughs at you. Hahahahaha, stupid script kiddie. Get a life.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help please!!

2007-02-11 Thread Gabriel Genellina
En Sun, 11 Feb 2007 16:40:45 -0300, darren112 [EMAIL PROTECTED]  
escribió:

 The program should support brute-forcing of the authentication process
 for a Telnet server via a dictionary attack.

You should first read the Python Tutorial. After you get proficient with  
the basic programming structures, reading and writing files, networking,  
then use the telnetlib module (included with the standard Python library)  
to write your program. Depending on your previous experience and daily  
time, that might take from a couple days to one or two months.

-- 
Gabriel Genellina

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


Re: help please!!

2007-02-11 Thread azrael
Hey yo kiddie, I hope that you are using the web for some time. So you
can get the meaning from my post.:


LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF,

my stomach hurts

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


Re: help please!!

2007-02-11 Thread James Stroud
darren112 wrote:
 Hi Im new to python and I desperately need help with this task
 This is everything of what I need to do...
 
 The program to be written in Python obviously..
 
 The program should support brute-forcing of the authentication process
 for a Telnet server via a dictionary attack.
 
 The python program is required to take four parameters: a) the IP
 address of a Computer, b) the port number that the Telnet server is
 running on the computer , c) the name of a file containing a list if
 usernames, and b) the name of a file containing a list of word/phrases
 to be used as passwords.
 
 The program should then attempt to authenticate itself to the Telnet
 server via trying every password for every username. The program
 should report when it is successful.
 
 Please help me And as I am new to all this please post step by
 step instructions...
 

I'm guessing this is a troll rather than a script kiddy. It seems more 
like bait than an honest question.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help please using telnetlib module

2006-12-24 Thread Birdman
Simplest explanation is that you can't do a 'show run' from global
configuration mode

try something like

#exit global configuration mode
tn.write('end\n')
print tn.read_until('#')

#disable pause after 24 lines
tn.write('term len 0\n')
tn.read_until('#')

#now show the entire running-config
tn.write('show run\n')
print tn.read_until('#')

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


Re: HELP PLEASE: What is wrong with this?

2006-04-15 Thread Sybren Stuvel
Ralph H. Stoos Jr. enlightened us with:
   File autotp.py, line 21
  ready = raw_input(Ready to proceed ? TYPE (y)es or (n)o: )
  ^

Please post the entire traceback, so we can see the actual error
message. Posting the context of the bad line also wouldn't hurt.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HELP PLEASE: What is wrong with this?

2006-04-15 Thread Thomas Jollans
Ralph H. Stoos Jr. wrote:

   File autotp.py, line 21
  ready = raw_input(Ready to proceed ? TYPE (y)es or (n)o: )
  ^
please post the entire output and the surrounding code (as much as
reasonable).
It may well be some paranthesis error, as alreasy stated.

-- 
Thomas Jollans - http://jollybox.de/
GNU/Linux - freedom, functionality, power - what more do you want ?
When in doubt, follow the penguins.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HELP PLEASE: What is wrong with this?

2006-04-14 Thread David Isaac
Ralph H. Stoos Jr. [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
   HELP PLEASE: What is wrong with this?File autotp.py, line 21
  ready = raw_input(Ready to proceed ? TYPE (y)es or (n)o: )
  ^

Probably the parenthesis you forgot to close on the preceding line ...

Cheers,
Alan Isaac


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


Re: HELP PLEASE: What is wrong with this?

2006-04-14 Thread Steve Bergman
Welcome to Python! :-)

You may find this mailing list useful:

http://mail.python.org/mailman/listinfo/tutor

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


Re: Help Please: 'module' object has no attribute 'compile'

2006-01-08 Thread livin
Oh, no I did not create any modules, wish I had the knowledge to do so!

I think I've moved beyond whatever that issue was and now getting a timeout. 
The info is below... any help you can give is appreciate!


I'm running this code...

import os, re, string, urllib, types
data = urllib.urlencode({'control_device': 'Kitchen Lights=on'})
urllib.urlopen('http://192.168.1.11', data)


and get this error log from Python...

File Q:\python\python23.zlib\urllib.py, line 78, in urlopen
File Q:\python\python23.zlib\urllib.py, line 183, in open
File Q:\python\python23.zlib\urllib.py, line 297, in open_http
File Q:\python\python23.zlib\httplib.py, line 712, in endheaders
File Q:\python\python23.zlib\httplib.py, line 597, in _send_output
File Q:\python\python23.zlib\httplib.py, line 564, in send
File Q:\python\python23.zlib\httplib.py, line 548, in connect
IOError
:
[Errno socket error] (10060, 'Operation timed out')


Kent Johnson [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 livin wrote:
 I beleive so... I cannot know for sure becasue the models are not 
 separate... they are in the python23.zlib file... I'm no sure how to 
 check the file, it looks as if it is compiled (I'm new to python so 
 forgive my ignorance)

 Yes, there should be an re module in your Python distribution, and it 
 should have a compile attribute. You can check this from the python 
 intepreter easily:
   import re
   re.compile
 function compile at 0x008FE0B0

 What I am suggesting is that YOU may have created a module named re that 
 Python is finding instead of the system module by that name. In this case 
 your module doesn't have a compile attribute. This would cause the error 
 you see.

 Kent



 Kent Johnson [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]

livin wrote:

my log...

INFO urllib.urlopen('http://192.168.1.11/hact/kitchen.asp', 
urllib.urlencode({'Action': 'hs.ExecX10ByName+Kitchen+Lights%2C+On 
%2C+100x=4y=6'}))
INFO
 INFO   File Q:\python\python23.zlib\urllib.py, line 78, in urlopen
INFO   File Q:\python\python23.zlib\urllib.py, line 159, in open
INFO   File Q:\python\python23.zlib\urllib.py, line 957, in splittype
INFO AttributeError
INFO :
INFO 'module' object has no attribute 'compile'

That line reads
_typeprog = re.compile('^([^/:]+):')

Do you have a module named 're' that is shadowing the library module of 
the same name?

Kent

 

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


Re: Help Please: 'module' object has no attribute 'compile'

2006-01-07 Thread livin
I beleive so... I cannot know for sure becasue the models are not 
separate... they are in the python23.zlib file... I'm no sure how to check 
the file, it looks as if it is compiled (I'm new to python so forgive my 
ignorance)


Kent Johnson [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 livin wrote:
 my log...

 INFO urllib.urlopen('http://192.168.1.11/hact/kitchen.asp', 
 urllib.urlencode({'Action': 'hs.ExecX10ByName+Kitchen+Lights%2C+On 
 %2C+100x=4y=6'}))
 INFO
  INFO   File Q:\python\python23.zlib\urllib.py, line 78, in urlopen
 INFO   File Q:\python\python23.zlib\urllib.py, line 159, in open
 INFO   File Q:\python\python23.zlib\urllib.py, line 957, in splittype
 INFO AttributeError
 INFO :
 INFO 'module' object has no attribute 'compile'

 That line reads
 _typeprog = re.compile('^([^/:]+):')

 Do you have a module named 're' that is shadowing the library module of 
 the same name?

 Kent 


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


Re: Help Please: 'module' object has no attribute 'compile'

2006-01-07 Thread Kent Johnson
livin wrote:
 I beleive so... I cannot know for sure becasue the models are not 
 separate... they are in the python23.zlib file... I'm no sure how to check 
 the file, it looks as if it is compiled (I'm new to python so forgive my 
 ignorance)

Yes, there should be an re module in your Python distribution, and it 
should have a compile attribute. You can check this from the python 
intepreter easily:
   import re
   re.compile
function compile at 0x008FE0B0

What I am suggesting is that YOU may have created a module named re that 
Python is finding instead of the system module by that name. In this 
case your module doesn't have a compile attribute. This would cause the 
error you see.

Kent

 
 
 Kent Johnson [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 
livin wrote:

my log...

INFO urllib.urlopen('http://192.168.1.11/hact/kitchen.asp', 
urllib.urlencode({'Action': 'hs.ExecX10ByName+Kitchen+Lights%2C+On 
%2C+100x=4y=6'}))
INFO
 INFO   File Q:\python\python23.zlib\urllib.py, line 78, in urlopen
INFO   File Q:\python\python23.zlib\urllib.py, line 159, in open
INFO   File Q:\python\python23.zlib\urllib.py, line 957, in splittype
INFO AttributeError
INFO :
INFO 'module' object has no attribute 'compile'

That line reads
_typeprog = re.compile('^([^/:]+):')

Do you have a module named 're' that is shadowing the library module of 
the same name?

Kent 
 
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help Please: 'module' object has no attribute 'compile'

2006-01-06 Thread Kent Johnson
livin wrote:
 my log...
 
 INFO urllib.urlopen('http://192.168.1.11/hact/kitchen.asp', 
 urllib.urlencode({'Action': 'hs.ExecX10ByName+Kitchen+Lights%2C+On 
 %2C+100x=4y=6'}))
 INFO
  INFO   File Q:\python\python23.zlib\urllib.py, line 78, in urlopen
 INFO   File Q:\python\python23.zlib\urllib.py, line 159, in open
 INFO   File Q:\python\python23.zlib\urllib.py, line 957, in splittype
 INFO AttributeError
 INFO :
 INFO 'module' object has no attribute 'compile'

That line reads
 _typeprog = re.compile('^([^/:]+):')

Do you have a module named 're' that is shadowing the library module of 
the same name?

Kent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help please with binary file read

2006-01-01 Thread Grant Edwards
On 2006-01-01, Stewart Arnold [EMAIL PROTECTED] wrote:

 I'm trying to convert a Real Basic routine into Python and I
 can't read the long integer data from a file.

http://docs.python.org/lib/module-struct.html

-- 
Grant Edwards   grante Yow!  Here I am in 53
  at   B.C. and all I want is a
   visi.comdill pickle!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help please with binary file read

2006-01-01 Thread Stewart Arnold
Grant

Perfect!

Thanks :)
Stewart

Grant Edwards [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 On 2006-01-01, Stewart Arnold [EMAIL PROTECTED] wrote:

 I'm trying to convert a Real Basic routine into Python and I
 can't read the long integer data from a file.

 http://docs.python.org/lib/module-struct.html


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


Re: Help please: How to assign an object name at runtime

2005-06-29 Thread Dan Sommers
On 29 Jun 2005 17:55:44 -0700,
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 The following is the input line of the file: SoftDict-.csv:
   ca1017,GRPHScriptSet,ADD/REM,Adobe Acrobat 4.0=2005/06/14

 I expected an instance of Machine() to be created with a name ca1017.

 Instead, an object is assigned to l[0] named:
__main__.Machine instance at 0x01282558

 -
 Here is my code:

[ ... ]

  machines = {}

 for line in FileList('SoftDict-.csv'): # Treat .csv as a text
 if len(line)==1: break# Quit processing; end of file
 l=line.split(',')# Split the line into constituent parts

Delete this:

 l[0]=Machine()# Create a Machine() object named: ca1017

And add this in its place:

  machines[l[0]] = Machine()

This will create a dictionary that maps the string 'ca1017' to a newly
created Machine object.

HTH,
Dan

-- 
Dan Sommers
http://www.tombstonezero.net/dan/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help please: How to assign an object name at runtime

2005-06-29 Thread John Machin
[EMAIL PROTECTED] wrote:
 Good day:
 Probably the answer to my question is staring me in the face, but the
 solution escapes me.
 
 The following is the input line of the file: SoftDict-.csv:
   ca1017,GRPHScriptSet,ADD/REM,Adobe Acrobat 4.0=2005/06/14
 
 I expected an instance of Machine() to be created with a name ca1017.

There is absolutely no basis at all for this expectation. How did you 
arrive at it?

 
 Instead, an object is assigned to l[0] named:
__main__.Machine instance at 0x01282558

The object is assigned to l[0] exactly as you dictated, i.e. its name is 
l[0]. The former referent of l[0] i.e. the string whose value is 
ca1017 is no longer in view and will be garbage-collected.

What are you really wanting to do?

BTW, don't use l.

 
 -
 Here is my code:
 
 class Machine:
 def __init__(self):
 self.software = []# Holds attributes of the instance

Do you mean like self.software ultimately =
['GRPHScriptSet', 'ADD/REM', 'Adobe Acrobat 4.0=2005/06/14'] ?

That's not quite what the man meant when he said 'object-oriented'!!

 def add(self, sware):
 self.software.append(sware)# Append attribute
 return self.software
 def show(self):
 return self.software
 def __call__(self):
 return [ e for e in self.software]

Isn't that the same as return self.software?

So obj.show() and obj() return an attribute of obj? That's an 
interesting interface.

Lose the __call__ -- you don't need it.


 def cnt(self):
 return '%s' % (len(self.software))

Why not just return the length as an integer???

 def installed(self, sware):
 if sware in self.software:
 return True
 else:
 return False

Try return sware in self.software

 
 class FileList:
 def __init__(self, filename):
 self.file = open(filename, 'r') # open and save file
 def __getitem__(self, i):   # overload indexing
 line = self.file.readline()
 if line:
 return line # return the next line
 else:
 raise IndexError# end 'for' loops, 'in'
 def __getattr__(self, name):
 return getattr(self.file, name) # other attrs
 
 
 if __name__ == '__main__':
 
 import sys, fileinput, os, string # when run, not imported
 
 for line in FileList('SoftDict-.csv'): # Treat .csv as a text
 if len(line)==1: break# Quit processing; end of file
 l=line.split(',')# Split the line into constituent parts
 l[0]=Machine()# Create a Machine() object named: ca1017
 ---
 
 That's it.  I evidently have no idea what I am doing.

The whole FileList class is pointless. Step 1: replace for line in 
FileList(filename):

with for line in open(filename):

and lose the if  : break line.

Step 2: read up on the csv module, and lose the split.

Step 3: you are unlikely to *ever* need the string and fileinput modules

Step 4: you import 4 modules you don't use. Why?

Oh and BTW Step 0: what are the requirements for this exercise, what do 
the fields in the file actually represent, what is that bloody = sign 
between 'Adobe Acrobat' and the date rrrggg words fail me [finally]


... exiting in pursuit of paracetamol,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help please: How to assign an object name at runtime

2005-06-29 Thread Steven D'Aprano
John Machin wrote:

 BTW, don't use l.

Excellent advice.

But since the original poster appears to be rather a 
newbie, perhaps a little bit of explanation would be 
useful.

Variables like l and I should be avoided like the 
plague, because in many fonts and typefaces they are 
indistinguishable, or look like the digit 1. Yes, I'm 
sure you are using a fancy syntax-highlighting editor 
that colours them differently, but the day will come 
that you are reading the code on pieces of dead tree 
and then you'll be sorry that you can't tell the 
difference between l and 1.

Another bit of advice: never use words like list, 
str, int etc as names for variables, because they 
conflict with Python functions:

py list(AB)
['A', 'B']
py list = []
py list(AB)
Traceback (most recent call last):
   File stdin, line 1, in ?
TypeError: object of type 'list' is not callable

In general, I only use single letter variable names 
like a, b, L (for a list), s (for a string) in short 
function code, where the nature of the variable is 
obvious from the context:

def stepsum(n, step=1):
 total = 0
 for i in range(0, n, step):
 total + i
 return total

def add_colon_str(s, t):
 return s + :  + t

It doesn't need much explanation to understand what s 
and t are. But for anything more complex, I always use 
descriptive names.


-- 
Steven.

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


Re: help please

2005-02-21 Thread rzed

gargonx [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Even if i put it in exactly the way you did:

  import re
  charmatcher = re.compile(r' [A-Z] [\d]?')
 
  ext = dict(D=V1, O=M1, G=S1)
  std = dict(S=H)
 
  decode_replacements ={}
  decode_replacements.update([(std[key], key) for key in std])
 Traceback (most recent call last):
   File stdin, line 1, in ?
 AttributeError: keys


Works with 2.4, but not with 2.3.4:

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type help, copyright, credits or license for more information.
 import re
 charmatcher = re.compile(r' [A-Z] [\d]?')

 ext = dict(D=V1, O=M1, G=S1)
 std = dict(S=H)

 decode_replacements ={}
 decode_replacements.update([(std[key], key) for key in std])

 print decode_replacements
{'H': 'S'}



Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on
win32
Type help, copyright, credits or license for more information.
 import re
 charmatcher = re.compile(r' [A-Z] [\d]?')

 ext = dict(D=V1, O=M1, G=S1)
 std = dict(S=H)

 decode_replacements ={}
 decode_replacements.update([(std[key], key) for key in std])
Traceback (most recent call last):
  File stdin, line 1, in ?
AttributeError: keys

 print decode_replacements
{}




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


Re: help please

2005-02-20 Thread gargonx
I think there's a problem with the code:

 py decode_replacements.update([(std[key], key) for key in std])
 py decode_replacements.update([(ext[key], key) for key in ext])

when i run this i get an error:
 AttributeError: keys

I can't get that figured out

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


Re: help please

2005-02-20 Thread Steven Bethard
gargonx wrote:
I think there's a problem with the code:
 py decode_replacements.update([(std[key], key) for key in std])
 py decode_replacements.update([(ext[key], key) for key in ext])
when i run this i get an error:
 AttributeError: keys
I can't get that figured out
Can you show the part of your code in which you do this?  As you can see 
from the interactive Python session I posted, I didn't get an 
AttributeError...

STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-20 Thread gargonx
Even if i put it in exactly the way you did:

 import re
 charmatcher = re.compile(r' [A-Z] [\d]?')

 ext = dict(D=V1, O=M1, G=S1)
 std = dict(S=H)

 decode_replacements ={}
 decode_replacements.update([(std[key], key) for key in std])
Traceback (most recent call last):
  File stdin, line 1, in ?
AttributeError: keys

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


Re: help please

2005-02-20 Thread Steven Bethard
gargonx wrote:
Even if i put it in exactly the way you did:
import re
charmatcher = re.compile(r' [A-Z] [\d]?')
ext = dict(D=V1, O=M1, G=S1)
std = dict(S=H)
decode_replacements ={}
decode_replacements.update([(std[key], key) for key in std])
Traceback (most recent call last):
  File stdin, line 1, in ?
AttributeError: keys
What version of Python are you using?  Here's what I get:
PythonWin 2.4 (#60, Nov 30 2004, 09:34:21) [MSC v.1310 32 bit (Intel)] 
on win32.
Portions Copyright 1994-2004 Mark Hammond ([EMAIL PROTECTED]) - 
see 'Help/About PythonWin' for further copyright information.
py
py import re
py charmatcher = re.compile(r' [A-Z] [\d]?')
py
py ext = dict(D=V1, O=M1, G=S1)
py std = dict(S=H)
py
py decode_replacements = {}
py decode_replacements.update([(std[key], key) for key in std])

As you can see, I'm using Python 2.4.  I'm guessing you're using an 
earlier version.  I just checked the docs for dict.update:

update() accepts either another mapping object or an iterable of 
key/value pairs (as a tuple or other iterable of length two). If keyword 
arguments are specified, the mapping is then is updated with those 
key/value pairs: d.update(red=1, blue=2). Changed in version 2.4: 
Allowed the argument to be an iterable of key/value pairs and allowed 
keyword arguments.

So dict.update() only accepts a list of key/value pairs as of 2.4 I 
guess.  Try:

py decode_replacements.update(dict([(std[key], key) for key in std]))
I believe that, unlike dict.update, the dict constructor allowed a list 
of key/value pairs previous to Python 2.4.  If that doesn't work either, 
you can do the more verbose version:

py for key in std:
... decode_replacements[std[key]] = key
...
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-20 Thread Steven Bethard
Dennis Lee Bieber wrote:
On 20 Feb 2005 20:12:50 -0800, gargonx [EMAIL PROTECTED] declaimed
the following in comp.lang.python:
decode_replacements.update([(std[key], key) for key in std])
Traceback (most recent call last):
 File stdin, line 1, in ?
AttributeError: keys
	Did you read the reference manual?
Yes, actually.  But I generally check only the reference manual for the 
current version of Python:

http://docs.python.org/lib/typesmapping.html
which does support sequence arguments for dict.update.  As noted there, 
of course, this support was added for Python 2.4.

STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-13 Thread Steven Bethard
gargonx wrote:
This works much better, aside from the fact that it does'nt work for
the std dictionary. the letters used from here stay the same. that
dictionary looks like this:
std = {
A:Z,
Z:A,
B:Y,
Y:B,
C:X,
X:C,
E:V,
V:E,
H:S,
S:H,
M:N,
N:M
}
what could be causing this?
i did figure out that if you reverse the k,v you are able to get it but
that doesn't turn up the results i need
def proc(text):
 result = []
 for word in text:
 for k, v in replacements:
 word = word.replace(v,k) #here i reversed them
 result.append(word)
 return ''.join(result)

The problem is that if you run all the replacements in std, you first 
translate As to Zs and then Zs to As.  If you want to do each character 
only once, you should probably write this as:

py std = {
... A:Z,
... Z:A,
... B:Y,
... Y:B,
... C:X,
... X:C,
... E:V,
... V:E,
... H:S,
... S:H,
... M:N,
... N:M}
py ext = {aa:i}
py punc = {,:!}
py replacements = {}
py replacements.update(punc)
py replacements.update(ext)
py replacements.update(std)
py def proc(text):
... result = []
... for char in text:
... result.append(replacements.get(char, char))
... return ''.join(result)
...
py proc('ABCDEFG')
'ZYXDVFG'
Or alternatively:
py def proc(text):
... return ''.join([replacements.get(c, c) for c in text])
...
py proc('ABCDEFG')
'ZYXDVFG'
Note however, that this won't work for multi-character strings like you 
had in 'ext' in your original example:

py proc('ABCaaEFG')
'ZYXaaVFG'
But neither would your original code.  Are the items in std always a 
single character?  Does ext always translate two characters to one? 
Could you give us some more info on the task here?

Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-13 Thread gargonx
yes the items in std are always single to single, and ext single to
double. basicly the ext are refernce to the std itmes. the second
character in ext is a number depending on how far it is from the item
in std. this is just a simple encoding program.

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


Re: help please

2005-02-13 Thread Steven Bethard
gargonx wrote:
yes the items in std are always single to single, and ext single to
double. basicly the ext are refernce to the std itmes. the second
character in ext is a number depending on how far it is from the item
in std. this is just a simple encoding program.
If your keys are always single characters (as this description seems to 
suggest) then the last code I posted should do what you want.  Repeated 
here for your enjoyment:

# merge mappings:
# std has highest precedence, then ext, then punc
replacements = {}
replacements.update(punc)
replacements.update(ext)
replacements.update(std)
# define encoding procedure
def proc(text):
# replace each character with its replacement
# or leave character unchanged if not in the mapping
return ''.join([replacements.get(c, c) for c in text])
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-13 Thread gargonx
Well that seems to work like a champion, but my prob then would be; how
do i get the double character values of ext to turn back to the single
character keys. The reversed (decode if you will). Thanks a lot Steve
this has been a great learning!

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


Re: help please

2005-02-13 Thread Steven Bethard
gargonx wrote:
Well that seems to work like a champion, but my prob then would be; how
do i get the double character values of ext to turn back to the single
character keys. The reversed (decode if you will).
It's unclear what you want to do here.  If you have say:
ext = dict(aa='A', ab='B', bb='C')
then how should 'aaabb' be decoded?  Some possibilities:
'ABb'
'AaC'
'aAC'
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-13 Thread gargonx
let's take the word dogs

   ext = dict(D:V1,  O:M1, G:S1)
   std = dict(S:H)

encode(DOGS) # proc()
we'll get: V1M1S1H

let's say i want to do just the opposite
word: V1M1S1H
decode(V1M1S1H)
#how do i decode V1 to D, how do i keep the V1 together?
and get: DOGS

#everything gets changed to uppercase

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


Re: help please

2005-02-13 Thread Steven Bethard
gargonx wrote:
let's take the word dogs
   ext = dict(D:V1,  O:M1, G:S1)
   std = dict(S:H)
encode(DOGS) # proc()
we'll get: V1M1S1H
let's say i want to do just the opposite
word: V1M1S1H
decode(V1M1S1H)
#how do i decode V1 to D, how do i keep the V1 together?
and get: DOGS
If you can make some assumptions about the right-hand sides of your 
dicts, you can probably tokenize your string with a simple regular 
expression:

py import re
py charmatcher = re.compile(r'[A-Z][\d]?')
py
py ext = dict(D=V1, O=M1, G=S1)
py std = dict(S=H)
py
py decode_replacements = {}
py decode_replacements.update([(std[key], key) for key in std])
py decode_replacements.update([(ext[key], key) for key in ext])
py
py def decode(text):
... return ''.join([decode_replacements.get(c, c)
... for c in charmatcher.findall(text)])
...
py
py decode(V1M1S1H)
'DOGS'
So, instead of using
for c in text
I use
for c im charmatcher.findall(text)
That gives me the correct tokenization, and i can just use the inverted 
dicts to map it back.  Note however that I've written the regular 
expression to depend on the fact that the values in std and ext are 
either single uppercase characters or single uppercase characters 
followed by a single digit.

Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-12 Thread Erik Max Francis
[EMAIL PROTECTED] wrote:
UnboundLocalError: local variable 't2' referenced before assignment
...
t2=
def Proc(text): # text is some random text or use OrigText
for word in text:
for letter in word:
if letter in std.keys():
letter=std[letter]
t2=t2+letter  # the problem is referene to this
elif letter in ext.keys():
letter=ext[letter]
t2=t2+letter
elif letter in punc.keys():
letter=punc[letter]
t2=t2+letter
can anyone figure out why t2 is not being used properly?
The problem is that you're not making it clear to Python that you want 
the t2 mentioned in Proc to reference the global t2, rather than a 
local.  It's concluding the latter, whereas you mean the former.  You 
can probably see that as a local, t2 is indeed referenced before it's 
assigned (t2 = t2 + letter).  The fix is to declare t2 global at the top 
of Proc:

def Proc(text):
global t2
...
--
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
San Jose, CA, USA  37 20 N 121 53 W  AIM erikmaxfrancis
  I am become death, the destroyer of worlds.
  -- J. Robert Oppenheimer (quoting Hindu legend)
--
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-12 Thread Steven Bethard
[EMAIL PROTECTED] wrote:
t2=
def Proc(text): # text is some random text or use OrigText
for word in text:
for letter in word:
if letter in std.keys():
letter=std[letter]
t2=t2+letter  # the problem is referene to this
elif letter in ext.keys():
letter=ext[letter]
t2=t2+letter
elif letter in punc.keys():
letter=punc[letter]
t2=t2+letter
As written, t2 is a global because of the statement at the top:
t2=
Inside Proc, the statement:
 t2=t2+letter  # the problem is referene to this
declares t2 as local to the function.  (Assignment to a name inside a 
function declares that name as local to the function.)  You could use 
the global keyword, but a better approach would be something like:

replacements = std.items() + ext.items() + punc.items()
def proc(text):
result = []
for word in text:
for k, v in replacements:
word = word.replace(k, v)
result.append(word)
return ''.join(result)
Now, instead of using a global 't2', I simply create a string and return 
it.  Note that I've also replaced your inefficient string addition with 
the more efficient list-append and list-join.

Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-12 Thread Steven Bethard
Erik Max Francis wrote:
[EMAIL PROTECTED] wrote:
UnboundLocalError: local variable 't2' referenced before assignment
...
t2=
def Proc(text): # text is some random text or use OrigText
...
The fix is to declare t2 global at the top of Proc:
def Proc(text):
global t2
...
But please don't.  The global declaration is a wart of Python, and in 
most cases, your code will be much cleaner if you avoid it.  Certainly 
in this case, making t2 a local of the function is much more sensible. 
If you stick with your current implementation (which I advise against), 
you should write it something like:

def proc(text):
t2 = 
...
# your Proc code here
...
return t2
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-12 Thread [EMAIL PROTECTED]
add just below the procedure declaration 'global t2'  as you're
referring to a global variable ...

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


Re: help please

2005-02-12 Thread gargonx
This works much better, aside from the fact that it does'nt work for
the std dictionary. the letters used from here stay the same. that
dictionary looks like this:

std = {
A:Z,
Z:A,
B:Y,
Y:B,
C:X,
X:C,
E:V,
V:E,
H:S,
S:H,
M:N,
N:M
}

what could be causing this?

i did figure out that if you reverse the k,v you are able to get it but
that doesn't turn up the results i need

def proc(text):
 result = []
 for word in text:
 for k, v in replacements:
 word = word.replace(v,k) #here i reversed them
 result.append(word)
 return ''.join(result)

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


Re: help please

2005-02-12 Thread gargonx
Thanks that works very well

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


Re: help please

2005-02-12 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
add just below the procedure declaration 'global t2'  as you're
referring to a global variable ...
More specifically, *modifying* it.  Just referring to it
doesn't require a global declaration...
-Peter
--
http://mail.python.org/mailman/listinfo/python-list