[Tutor] Beginner question (variables, namespaces...)

2006-04-07 Thread Jesse
Why is it that when one variable is assigned a value in terms of another variable, assigning a new value to the first doesn't change the value of the second? This is giving me a huge headache, since I have a bunch of variables defined in terms of one another, and I want to be able to dynamically update them (I did not include the definitions of the functions overstock and roundup, but they work): 

 
stock = float(raw_input("Enter stock (in terms of portions: "))container = float(raw_input("Enter portions per container: "))price_per_container = float(raw_input("Enter price per container: ")) 
weekly_quota = float(raw_input("Enter quota (in terms of portions): "))extra = overstock(stock, weekly_quota)  # overstock returns 0 if the first argument is less than the second; otherwise it returns the 

  difference between the first argument and the second.need = weekly_quota - extrabuy_containers = roundup(need/container) # roundup rounds a non-integer to the next highest integer 
buy_portions = buy_containers * containerleftover = buy_portions - needcost = price_per_container * buy_containers
 
I would like to write a function that will update the values of the above variables given an increase in only the stock variable. Otherwise I'd have to repeat a bunch of code...:(
 
Jesse
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] n00b question: dictionaries and functions.

2006-04-12 Thread Jesse
Hey, this should be an easy question for you guys. I'm writing my first program (which Bob, Alan, and Danny have already helped me with--thanks, guys!), and I'm trying to create a simple command-line interface. I have a good portion of the program's "core functions" already written, and I want to create a dictionary of functions. When the program starts up, a global variable named command will be assigned the value of whatever the user types:

 
command = raw_input("Cmd > ")
 
If command is equivalent to a key in the dictionary of functions, that key's function will be called. Here's an example that I wrote for the sake of isolating the problem:
 

def add():    x = float(raw_input("Enter a number: "))    y = float(raw_input("And a second number: "))    print x + ydef subtract():    x = float(raw_input("Enter a number: "))
    y = float(raw_input("And a second number: "))    print x - y    
commands = {"add": add(), "subtract": subtract()} 
Now, before I could even get to writing the while loop that would take a command and call the function associated with that command in the commands dictionary, I ran this bit of code and, to my dismay, both add() and subtract() were called. So I tried the following:

 
def add(x, y):
    x = float(raw_input("Enter a numer: "))
    y = float(raw_input("And a second number: "))
add = add()
 
When I ran this, add() was called. I don't understand why, though. Surely I didn't call add(), I merely stored the function call in the name add. I would expect the following code to call add:
 

def add(x, y):
    x = float(raw_input("Enter a numer: "))
    y = float(raw_input("And a second number: "))
add = add()
add
 
Can someone clear up my misunderstanding here? I don't want to end up writing a long while loop of conditional statements just to effect a command-line interface.
 
-Jesse
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] A simple solution to the even/odd problem

2006-04-20 Thread Jesse
Hey, I'm a Python newbie, and I'm not even sure I've correctly interpreted the problem, but from what I gather the idea is to take an integer with an arbitrary number of digits and return two [strings/lists/tuples/whatever]: one containing all of the odd digits, and another containing all of the even digits. This should work:

 

def make_string(words):    string = " "    for x in words:    string = string + x + " "    return string
def even_odd(num):    even = []    odd = []    num_string = str(num)    for x in num_string:    a = int(x)    if a%2 == 0:    even.append(x)    else:    
odd.append(x)    odd_string = make_string(odd)    even_string = make_string(even)    return (odd_string, even_string) 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Removing/Handing large blocks of text

2004-12-08 Thread Jesse Noller
Hello,

I'm trying to do some text processing with python on a farily large
text file (actually, XML, but I am handling it as plaintext as all I
need to do is find/replace/move) and I am having problems with trying
to identify two lines in the text file, and remove everything in
between those two lines (but not the two lines) and then write the
file back (I know the file IO part).

I'm trying to do this with the re module - the two tags looks like:


...
a bunch of text (~1500 lines)
...


I need to identify the first tag, and the second, and unconditionally
strip out everything in between those two tags, making it look like:




I'm familiar with using read/readlines to pull the file into memory
and alter the contents via string.replace(str, newstr) but I am not
sure where to begin with this other than the typical open/readlines.

I'd start with something like:

re1 = re.compile('^\')
re2 = re.compile('^\<\/foo\>')

f = open('foobar.txt', 'r')
for lines in f.readlines()
match = re.match(re1, line)

But I'm lost after this point really, as I can identify the two lines,
but I am not sure how to do the processing.

thank you
-jesse
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Removing/Handing large blocks of text

2004-12-09 Thread Jesse Noller
On Wed, 8 Dec 2004 15:11:55 +, Max Noel <[EMAIL PROTECTED]> wrote:
> 
> 
> 
> On Dec 8, 2004, at 14:42, Jesse Noller wrote:
> 
> > Hello,
> >
> > I'm trying to do some text processing with python on a farily large
> > text file (actually, XML, but I am handling it as plaintext as all I
> > need to do is find/replace/move) and I am having problems with trying
> > to identify two lines in the text file, and remove everything in
> > between those two lines (but not the two lines) and then write the
> > file back (I know the file IO part).
> 
> Okay, here are some hints: you need to identify when you enter a 
> block and when you exit a  block, keeping in mind that this may
> happen on the same line (e.g. blah). The rest is trivial.
> The rest of your message is included as a spoiler space if you want to
> find the solution by yourself -- however, a 17-line program that does
> that is included at the end of this message. It prints the resulting
> file to the standard out, for added flexibility: if you want the result
> to be in a file, just redirect stdout (python blah.py > out.txt).
> 
> Oh, one last thing: don't use readlines(), it uses up a lot of memory
> (especially with big files), and you don't need it since you're reading
> the file sequentially. Use the file iterator instead.
> 
> 
> 
> > I'm trying to do this with the re module - the two tags looks like:
> >
> > 
> > ...
> > a bunch of text (~1500 lines)
> > ...
> > 
> >
> > I need to identify the first tag, and the second, and unconditionally
> > strip out everything in between those two tags, making it look like:
> >
> > 
> > 
> >
> > I'm familiar with using read/readlines to pull the file into memory
> > and alter the contents via string.replace(str, newstr) but I am not
> > sure where to begin with this other than the typical open/readlines.
> >
> > I'd start with something like:
> >
> > re1 = re.compile('^\')
> > re2 = re.compile('^\<\/foo\>')
> >
> > f = open('foobar.txt', 'r')
> > for lines in f.readlines()
> > match = re.match(re1, line)
> >
> > But I'm lost after this point really, as I can identify the two lines,
> > but I am not sure how to do the processing.
> >
> > thank you
> > -jesse
> > ___
> > Tutor maillist  -  [EMAIL PROTECTED]
> > http://mail.python.org/mailman/listinfo/tutor
> 
> #!/usr/bin/env python
> 
> import sre
> 
> reStart = sre.compile('^\s*\')
> reEnd = sre.compile('\\s*$')
> 
> inBlock = False
> 
> fileSource = open('foobar.txt')
> 
> for line in fileSource:
>  if reStart.match(line): inBlock = True
>  if not inBlock: print line
>  if reEnd.match(line): inBlock = False
> 
> fileSource.close()
> 
> -- Max
> maxnoel_fr at yahoo dot fr -- ICQ #85274019
> "Look at you hacker... A pathetic creature of meat and bone, panting
> and sweating as you run through my corridors... How can you challenge a
> perfect, immortal machine?"
> 
> 


Thanks a bunch for all of your fast responses, they helped a lot -
I'll post what I cook up back to the list as soon as I complete it.
Thanks!

-jesse
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Syntax Problem

2009-07-24 Thread Jesse Harris
for d in Decks.all(): #loop thru all available decks
  self.response.out.write(''+d.name) 
      self.response.out.write(''+d.description)
self.response.out.write('')
self.response.out.write('')

: invalid syntax (main.py, line 206)

  args =
('invalid syntax', (r'C:\Program 
Files\Google\google_appengine\bangagears2\main.py', 206, 78, "
\t\tself.response.out.write(''+d.description)\n"))

  filename =
r'C:\Program Files\Google\google_appengine\bangagears2\main.py'

  lineno =
206

  message =
''

  msg =
'invalid syntax'

  offset =
78

  print_file_and_line =
None

  text =
"
\t\tself.response.out.write(''+d.description)\n"









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


[Tutor] Accessing windows from Linux build

2009-09-28 Thread Jesse L
I want to use a linux system to scan windows registries for a specific key.
I know there is the _winreg module, but it's only available on a windows
system.  Is there a module that will enable python to work cross platform?

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


Re: [Tutor] SSH using python

2007-06-04 Thread Jesse Noller

On 6/4/07, Chandrashekar <[EMAIL PROTECTED]> wrote:


Hi ,

Can anyone tell me how to do ssh to a machine using python and execute
programs on the remote machine? Thanks in advance.

Regards,
Chandru

--
Boardwalk for $500? In 2007? Ha!
Play Monopoly Here and 
Now(it's
 updated for today's economy) at Yahoo! Games.


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



pSSH:
http://www.theether.org/pssh/

Paramiko:
http://www.lag.net/paramiko/

pExpect example:
http://www.palovick.com/code/python/python-ssh-client.php

Twisted Conch:
http://twistedmatrix.com/users/z3p/files/conch-talk.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SSH commands in Python on Linux

2005-08-11 Thread Jesse Noller
On 8/10/05, Bernard Lebel <[EMAIL PROTECTED]> wrote:
> Hello,
> 
> I'm trying to make a script to send a SSH command from a Linux
> computer to another Linux compter.
> 
> The Python syntax I'm using...
> 
> 
> import os
> os.system( 'ssh [EMAIL PROTECTED] "ls"' )
> 
> 
> Now the problem is that I'm always asked for the password. So my
> question is two-fold:
> 
> 1- Is there a way to not be asked for the root password?
> 2- If not, then is it possible to feed the SSH password input with my
> Python script? I have about stdin redirection, but I have to admit
> that I'm a bit lost and I don't know if it applies to SSH input as
> well.
> 
> Right now I'm using the ls command to list processes, however
> ultimately I want to be able to kill some processes within a loop
> (this is for render farm management).
> 
> 
> 
> Thanks
> Bernard

Some of the things you are going to be bit by you've already ran into
- the first of which is authentication.

I would recommend looking at the following utilities:

http://www.theether.org/pssh/
http://sourceforge.net/projects/pyssh

Setting up private/public key authentication is going to allow for a
greate amount of secure automation. Barring that, use the pexpect
module to do the prompt handling, pexpect is bad simply due to the
fact you'll need to store your passwords plaintext within your program
which is a seriously risk.

Also note you'll need to take into account basic flow control for
Stdin, Stdout and Stderr - you need to watch for hosts that are not
found/don't exist and ssh commands that may or may not hang.

The PSSH program has excellent work arounds for all of these within it. 

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


[Tutor] re

2005-08-13 Thread Jesse Lands
I am trying to create a simple GUI that will track a network connection using 
ping.  It's a starter project for me so I am sure there are other easier ways 
of doing it, but I am learning, so bare with me.  

I figured out the first part 

import os
ping = os.popen('ping -c 4 10.0.8.200')
ping_result = ping.read()


I assume I have to use Regular Expression to read the results, but I don't 
quite understand it.  Can someone explain it or point me in a direction to 
where it's explained better then what I could find with google.

TIA
Jesse
-- 
JLands
Arch Current(Laptop)
Slackware 9.1(Server)
Slackware Current(Desktop)
Registered Linux User #290053
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello

2005-08-24 Thread Jesse Lands
On Wed, 24 Aug 2005 16:49:17 -0700 (PDT)
Eric Walker <[EMAIL PROTECTED]> wrote:

> all,
> Hello... I just finished a class given by Mark Lutz
> and I love python. Now I need to find a project to
> hone my skills. I am sure I will be sending lots of
> questions to this list.  I used to use perl but now
> Its gone. I am now a Python guy... Hail Guido

How was the class?  I am taking a class that Mark Lutz is teaching in October. 
Is it worth it?
Thanks

-- 
JLands
Arch Current(Laptop)
Slackware 9.1(Server)
Slackware Current(Desktop)
Registered Linux User #290053
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2018-10-27 Thread Jesse Stockman
Hi there 

I need to draw a patten with turtle in python 3.7 but I cant get it to work 
here are the specs of the pattern and my code so far can you please help

• Specifications of the pattern o The radius of the three heads is 10. 
o The length of legs is 30. o The length of the sizes of the two triangles (the 
body of runner-up and third-place) is 40. They are all equal-size triangles. 
The winner’s body is a 40x40 square. o The width of the three blocks of the 
podium is 60. The heights are 90, 60, and 40 respectively. 

And my code so far

from turtle import *

x = 0
y = 0
radius = 0
x1 = 0
x2 = 0
y1 = 0
y2 = 0
color = 0
width = 0
hight =0



def main():
speed(0)
pensize(3)
pencolor("black")

winner_color = "red"
second_color = "orange"
third_color = "purple"
draw_podium(winner_color, second_color, third_color)
darw_third(third_color)
draw_winner(winner_color)
draw_second(second_color)

def move_to(x, y):
x = int(input("input X coordinate: "))
y = int(input("input y coordinate: "))
penup()
goto(x, y)
pendown()

def draw_head(x, y, radius):
radius = int(input("input radius: "))
move_to(x, y)
circle(radius)

def draw_line(x1, y1, x2, y2):
x1 = int(input("line start X: "))
y1 = int(input("line start Y: "))
x2 = int(input("line end X: "))
y2 = int(input("line end Y: "))
penup()
goto(x1,y1)
pendown()
goto(x2,y2)

def draw_block(x, y, hight, width, color):
move_to(x, y)
hight = int(input("input hight: "))
width = int(input("input width: "))
color(winner_color)
begin_fill()
forward(width)
left(90)
forward(hight)
left(90)
forward(width)
left(90)
forward(hight)
end_fill()

 
main()
draw_block(x, y, hight, width, color)


exitonclick()
 

please help me
thank you
kind regards
Tarantulam


Sent from Mail for Windows 10

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


[Tutor] Fw: [docs] Fw: Embedding Python in Another Application Import Statement Bug

2019-07-08 Thread Ibarra, Jesse
I cannot seem to figure this potential bug out.

Please advise,

Jesse Ibarra



From: Julien Palard 
Sent: Sunday, July 7, 2019 2:02 PM
To: Ibarra, Jesse
Cc: d...@python.org
Subject: Re: [docs] Fw: Embedding Python in Another Application Import 
Statement Bug

Hi

> Is this ticket still unsolved?

I do not have a CentOS to try it. You can try on 
https://mail.python.org/mailman/listinfo/tutor list maybe, and if you resolve 
your issue and it happen to be documentation related, don't hesitate to let the 
docs@ list know.

Bests,
--
Julien Palard
https://mdk.fr

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


[Tutor] Fw: [docs] Python Embedding PyImport_ImportModule

2019-07-08 Thread Ibarra, Jesse
I cannot seem to figure this potential bug out.

Please advise,

Jesse Ibarra



From: Julien Palard 
Sent: Sunday, July 7, 2019 2:04 PM
To: Ibarra, Jesse
Subject: Re: [docs] Python Embedding PyImport_ImportModule

Hi Jesse,

> Why does this code only print the result(array([ 1.,  1.,  1.,  1.,  1.])) 
> once, when I am calling the python code twice?

You're on a mailing list about Python documentation, not embedding support. 
Have you tried https://mail.python.org/mailman/listinfo/tutor?

Bests,
--
Julien Palard
https://mdk.fr

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


Re: [Tutor] RE Embedding Python in C

2019-07-09 Thread Ibarra, Jesse
Sorry for the duplicate threads but the forwarded message did not send the 
original email. I apologize for any inconvenience.
The file are below.

I am running CentOS7:

[jibarra@redsky ~]$ uname -a
Linux redsky.lanl.gov 3.10.0-957.21.2.el7.x86_64 #1 SMP Wed Jun 5 14:26:44 UTC 
2019 x86_64 x86_64 x86_64 GNU/Linux

I am using Python3.6:
[jibarra@redsky ~]$ python3.6
Python 3.6.8 (default, Apr 25 2019, 21:02:35)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>


I was sucessfully ran example:
https://docs.python.org/3.6/extending/embedding.html#very-high-level-embedding

I am sucessfully ran 
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html
 example and named it Rosenbrock_Function.py:

from scipy.optimize import minimize, rosen, rosen_der
x0 = [1.3, 0.7, 0.8, 1.9, 1.2]
res = minimize(rosen, x0, method='Nelder-Mead', tol=1e-6)
print(res.x)

I then embedded the example using C/Python API:
https://docs.python.org/3.6/extending/embedding.html#pure-embedding

int main(){
  PyObject *pModule, *pName;

  Py_Initialize();
  PyRun_SimpleString("import sys");
  PyRun_SimpleString("sys.path.append('.')");

  pModule = PyImport_ImportModule("Rosenbrock_Function");
  pName = PyImport_ImportModule("Rosenbrock_Function");

  Py_XDECREF(pModule);
  Py_XDECREF(pName);

  Py_Finalize();

  return 0;
}


Why does this code only print the result(array([ 1.,  1.,  1.,  1.,  1.])) 
once, when I am calling the python code twice?

Please advise,
Jesse Ibarra

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


[Tutor] Calling a C shared library with PyObject

2019-07-17 Thread Jesse Ibarra
I am using Python3.6

Working with C/Python embedding:
https://docs.python.org/3.6/extending/embedding.html#beyond-very-high-level-embedding-an-overview

I have to call a shared library (.so) that I created using PyObjects.

Please advise.

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