[Tutor] Is this a good idea?

2007-06-05 Thread Carlos
Hello,

I'm trying to generate two classes, one of them is a given object and 
the other is a 'factory' of those objects. I'm doing this because I'm 
working with huge amounts of objects and would like to have a loop 
generating them. The problem is that I fear that my understanding of OOP 
is just not good enough. So what do you say, is this a good way to solve 
this??

class objct:

   def __init__(self, name, val):
   self.name = name
   self.val = val
  class collection:

   def __init__(self, objcts):
 objecList = []

   for i in range(objcts):
   instance = 'myInst%i' %(i)
   objecList.append(instance)

   for i in range(objcts):
   i = objct(objecList[i], i)
   print i.name
   print i.val
  myC = collection(10)

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


[Tutor] Get max quantity

2007-06-13 Thread Carlos
Hello,

If I have a dictionary like:

inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}

How can I get the item with the largest quantity? I tried:

max(inventory)

but got:

'pears'

What I would like to get is 'oranges', at least in this case.

Thanks,
Carlos

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


[Tutor] CGKit

2006-10-03 Thread Carlos
Hi,

I'm new to python and have been trying to install CGKit, it has a bunch 
of dependencies that I have to install. /At this point /the problem that 
I have is that I need to install Py++, I already installed pygccxml and 
GCC-XML. To install Py++ I downloaded it, and extracted it, next I 
opened a windows command prompt and went to the corresponding directory, 
then I typed "python setup.py install" this is supposed to install the 
package? Because I only get a message from windows that states that to 
install anything I must go to the control panel. Can you tell me where 
is the mistake?

By the way, has someone managed to install CGKit and can guide me in the 
process? I'm having a lot of trouble with it.

This is the page, just in case http://cgkit.sourceforge.net

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


Re: [Tutor] CGKit

2006-10-03 Thread Carlos
Thanks Luke and Kent,

To get CGKit running I need to do two different things:

First the Python Computer Graphics Kit is composed by an 
"cgkit-2.0.0alpha6.win32-py2.4.exe" file and some dependencies that are 
PyProtocols, numarray, PyOpenGL, PIL, pygame, PyODE and pySerial, with 
the exception of PyProtocols I have installed all of them. When I try to 
install PyProtocols from the command prompt it tells me that " The .NET 
Framework SDK needs to be installed before building extensions for 
Python." I went to Microsoft and installed the "Microsoft .NET Framework 
SDK v2.0", but the problem persists.

The second part is the Python Maya Plug-In. I think that this is the 
tricky one, it is asking me to install Py++, that I have already 
installed. Now my problem comes when I have to compile the source code 
with Boost.Python, this one asks for Boost Jam and Boost. I have been 
trying to install this things but still have no clue at how.

Thanks for your help
Carlos




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


Re: [Tutor] CGKit

2006-10-05 Thread Carlos
Hi Kent,

Probably I'm totally missing something, but...

I think there is not a compiled plug-in, if you go here 
http://cgkit.sourceforge.net/#download you are going to see that : " The 
Maya Python package (i.e. the Maya plug in and the actual Python 
package) is a separate package that can be downloaded from the above 
page as well. Currently, only the sources are available."

The pages that you are pointing are installation instructions, but they 
not point to the compiled plug-in. If you go to the project download 
page <http://cgkit.sourceforge.net/#support>  you will see the cgkit and 
maya sections, inside the maya section there are some files, but none of 
them is the plug-in itself, only the sources (I think). I have found 
that you can compile the plug-ins with scons instead of boost and seems 
to be easier. I just need to now how to set some paths. Here is what the 
readme of the file says:


"The plugin is built using SCons (www.scons.org). If necessary, you can 
do customizations in a file config.py where you can set additional 
include paths and library paths in the lists CPPPATH and LIBPATH. Example:

CPPPATH = ["...path1...", "...path2...", ...]
LIBPATH = ["...path1...", "...path2...", ...]

You have to make sure that the Maya SDK and the Python SDK can be found. 
To compile the plugin you have to call "scons" in the root directory of 
the sourcepy plugin (where the SConstruct file is located). If 
everything went fine, the result will be in the bin subdirectory (the 
file will be called sourcepy.mll or sourcepy.so) from where you can copy 
it to any convenient place where Maya is able to find it."

I hope that someone can tell me how to do this.
Carlos



""

Thanks
Carlos

Kent Johnson wrote:
> Carlos wrote:
>> Thanks Luke and Kent,
>>
>> To get CGKit running I need to do two different things:
>>
>> First the Python Computer Graphics Kit is composed by an 
>> "cgkit-2.0.0alpha6.win32-py2.4.exe" file and some dependencies that 
>> are PyProtocols, numarray, PyOpenGL, PIL, pygame, PyODE and pySerial, 
>> with the exception of PyProtocols I have installed all of them. When 
>> I try to install PyProtocols from the command prompt it tells me that 
>> " The .NET Framework SDK needs to be installed before building 
>> extensions for Python." I went to Microsoft and installed the 
>> "Microsoft .NET Framework SDK v2.0", but the problem persists.
>>
>> The second part is the Python Maya Plug-In. I think that this is the 
>> tricky one, it is asking me to install Py++, that I have already 
>> installed. Now my problem comes when I have to compile the source 
>> code with Boost.Python, this one asks for Boost Jam and Boost. I have 
>> been trying to install this things but still have no clue at how.
>
> Use the compiled plug-in. This page:
> http://cgkit.sourceforge.net/mayadoc/install.html
> says to copy sourcepy.mll to the Maya plug-in directory.
>
> Python extensions for Windows are usually distributed as binaries 
> because so many people do not have the resources and knowledge to 
> compile them. I don't see anything in the Maya plugin docs to indicate 
> that you have to build it from source.
>
> Kent
>
>
>


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


Re: [Tutor] CGKit

2006-10-05 Thread Carlos
Hi Kent,

Thanks for the info, I will send a mail to the plug-in developer.

I didnt mention this before, Im an architect and my master thesis 
semester is beginning now. Last semester I was introduced to what is 
somehow known as morphogenetic design, to programming and to python. 
 From that semester a small python script came, that generated a 
structure composed by struts and tensor cables inside of maya, anyway, 
this semester I want to use programming again, this stuff has really 
convinced me that can be useful in the design field. My idea is to 
create a script that will deal with the spatial organization of a 
housing block, it would be very interesting to see it generating a 
number of solutions and evolving them a number of times until it can 
find an "optimum" solution.

What I would like to know is, does this sounds too complex for a 
newcomer like me? If by chance anyone has some experience that can share 
I would be grateful.

I know that this is a little off topic, in the future I will try to keep 
this more centered on python.

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


[Tutor] M Arch Thesis

2006-10-31 Thread Carlos
Hi to all,

For my Thesis project, I want to use a Genetic Algorithm to generate 
multiple spatial organization solutions for Architectural projects. My 
idea is that a software that does this would be useful as a rapid 
prototyping tool and more important it will probably reach solutions 
that a human user would not. The problem is that I can't find a GA 
module for python that is reasonably easy to use, do you know if there 
is something out there that can help me? I would like to find something 
with a black box approach, in this case I would only need to feed the 
system some information and get a result in the end, forgetting a little 
about the process itself. Dont think me lazy is just that I'm new to 
python and my time is limited.

By the way, do you think that a GA solution is good for this project, 
maybe someone has a better idea.

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


[Tutor] First real script

2006-11-06 Thread Carlos
Hello to all,

This is my first script, I mean the first that I'm trying to do on my 
own. Its a very simple Cellular Automata thing, the idea is that the 
initial list A_List is rewritten based on some rules, in this case 
Wolfram's rule 30. You can modify the list length and its initial state, 
you can also set the number of iterations.

What I would like is to see how it can be improved. The basic 
functionality is done, I just want to listen some advise from experts 
like you : )

For example how can I improve the way in which the rules are written? 
Would you use the same method that I have chosen?

And what about the if and else that are right after the two loops? they 
are there because if not when the loop gets to the last number an 
exception arises.

Thanks a lot
Carlos

Here is the code:
Note: Right now maya is not needed to run the code.

#My first try at Cellular Automata
#A very basic script that lets you play with Wolfram's rule 30
#if you wish to see the results in maya, you will need CGKit and Maya

#from maya.api import *
#from maya.mel import *
import time

#This is the initial state. You can put as many integers as you wish
A_List = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]

A_Len = len(A_List)
print 'A_List: ',A_List
print 'A_Len: ', A_Len
B_List = []
S = A_Len
print S

#This is the number of iterations.
for r in range (50):

for i in range (S):

#if i < S-1:
   
a = A_List[i-1]
b = A_List[i]
c = A_List[i+1]

else:

a = A_List[i-1]
b = A_List[i]
c = A_List[0]
   
   
if a == 1 and b == 1 and c == 1:
X = 0
elif a == 1 and b == 1 and c == 0:
X = 0
elif a == 1 and b == 0 and c == 1:
X = 0
elif a == 1 and b == 0 and c == 0:
X = 1
elif a == 0 and b == 1 and c == 1:
X = 1
elif a == 0 and b == 1 and c == 0:
X = 1  
elif a == 0 and b == 0 and c == 1:
X = 1
elif a == 0 and b == 0 and c == 0:
X = 0

#print i,a,b,c,X
#if X == 1:
#print r,i,X
#polyCube()
#move(r=(i,r,0))
B_List.append(X)

print 'B_List: ',B_List
A_List = B_List
B_List = []

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


Re: [Tutor] First real script

2006-11-06 Thread Carlos
Hi again,

Thanks for your comments they are really appreciated.

Alan, yes you are right, there is no need to use S, A_Len works the same 
way. Beginner mistake

The dictionary way seems to be way better than my idea, will give it a try.

And Danny, your CA is very nice.

Do you know a better way to do this?

if i < A_Len-1:
   
a = A_List[i-1]
b = A_List[i]
c = A_List[i+1]

else:

a = A_List[i-1]
b = A_List[i]
c = A_List[0]

if I dont do this I get the following error:

c = A_List[i+1]
IndexError: list index out of range

I have the impression that this can be done in a less clunky way.

Again thanks for your comments.  : )

Best Regards,
Carlos.


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


Re: [Tutor] First real script

2006-11-07 Thread Carlos
Hello to all,

Ok, after reading your comments I ended up with this:

#Easy_2DCA_01.py
#A very basic 2D script that lets you play with Wolfram's rule 30

A_List = [0]*10+[1]+[0]*10
A_Len = len(A_List)
B_List = []
print A_List
Iterations = 5

rule_30 = {
  (1, 1, 1) : 0,
  (1, 1, 0) : 0,
  (1, 0, 1) : 0,
  (1, 0, 0) : 1,
  (0, 1, 1) : 1,
  (0, 1, 0) : 1,
  (0, 0, 1) : 1,
  (0, 0, 0) : 0,
}

for j in range (Iterations):
for i in  range (A_Len):

x = A_List[i-1]
y = A_List[i]

if i < A_Len-1:
z = A_List[i+1]

else:
z = A_List[0]
   
X = rule_30[x,y,z]

B_List.append (X)
   
print B_List
A_List = B_List
B_List = []

Not bad I think :P It is compact and readable, even by a dummy like me. 
I took the ideas that I completely understand, there are others that are 
slightly too much for me now, but they are noted too.

I want to thank all you guys for the comments. This is my first script, 
but I can see that this list a great resource for learning Python.

As you may have noticed the name of the script has changed, I will now 
try a 3D CA. I have been thinking that the best way to do this would be 
to use a matrix, like those found in SciPy. Do you think this is a good 
idea? I'm afraid that my reasoning is too linear, to add another 
dimension to my script I will add another dimension to my initial list.

Here is an example:

import scipy
a1 = scipy.zeros((4,5))
print a1
[[ 0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.]]

Thats it for now.

Thanks again,
Carlos

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


Re: [Tutor] First real script

2006-11-08 Thread Carlos
Hi Again,

Luke, I left it this way now:

x = A_List[i-1]
y = A_List[i]
z = A_List[(i+1) % A_Len]

Probably the other way is shorter but right now I feel comfortable as it 
is now :-[ , Danny had already mentioned this method before, but it 
didn't sink properly until now. And yes I need it to wrap around because 
if not the behavior changes, at least it happened in my tests.

Now I'm tring to make it possible to choose which rule to use, my first 
idea was:

R_30 = [0,0,0,1,1,1,1,0]
R_110 = [0,1,1,0,1,1,1,0]
R = R_110
rule = {
  (1, 1, 1) : R[0],
  (1, 1, 0) : R[1],
  (1, 0, 1) : R[2],
  (1, 0, 0) : R[3],
  (0, 1, 1) : R[4],
  (0, 1, 0) : R[5],
  (0, 0, 1) : R[6],
  (0, 0, 0) : R[7],
}

I believe that in this way all possible rules could be defined by a 
list. The problem is that I'm going to need 256 lists. What would be 
real nice is to input a number, lets say 30 and have it converted to 
binary notation so it would look like 1110, then add enough zeros to the 
left and end up with 0001110, and finally convert this to a list than 
can be referenced in the dictionary. Here is the code:

#This is a hacked version of 'tobinary' from:
#http://gnosis.python-hosting.com/voting-project/OVC-Demo2/att-0020/convert.py

def tobinary(dec):
"""Convert a decimal number to binary.

Parameters:
dec: The decimal number
"""
   
bin = []
while dec > 0:
bit = int(dec % 2)
bin.insert(0, bit)
dec = (dec - bit)/2
print bin

##This area formats a Bin number between 0 and 255
##so it conforms with CA rules formatting
   
b_len = len(bin)
print 'b_len: ', b_len
while b_len < 8:
bin[0:0] = [0]
b_len = len(bin)
print bin
   

tobinary(30)

Is this a good way to proceed?

Alan, about going 3D, I agree a normal 2D list will do, but I'm really 
afraid of the list wrapping, this time squared (or is it cubed?). I'm 
going to need rules for center, corner and border cells. I'm afraid...

Thanks  a lot,
Carlos
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First realscript + Game of Life

2006-11-09 Thread Carlos




Hallo to All,

Hey Rooy, so its possible to copy binary numbers from memory? I had the
impression that this could be done, but obviously it is too much for
me. This way is going to be faster than the hack that I tried before,
right? Thanks for the  module : )

Now I'm tring to implement a Conway's
Game of Life in Maya with CGKit. It was going well until I got this
error:

Traceback (most recent call last):
  File "", line 14, in ?
  File "test.py", line 31, in ?
    Neighbor_Value = BOX_State[i-11]+BOX_State[i-10]+BOX_State[i-9]+\
IndexError: list index out of range

I know what it means, but I just can't figure out why this happens when
the loop reaches 89. Can someone please tell me the reason for this?
Here is my code so far:

from maya.mel import *
from random import *

BOX_List = []
BOX_State = []

rows = 10
columns = 10

for x in range (rows):
    for z in range(columns):
    State = randint(0,1)
    Name = 'BOX_%i_%i'%(x,z)
    BOX_List.append(Name)
    BOX_State.append(State)
    if State == 1:
                polyCube(name = (Name))
                move(z,0,x)

for i in range (rows*columns):

    Cell_Value = BOX_State[i]

    Neighbor_Value = BOX_State[i-11]+BOX_State[i-10]+BOX_State[i-9]+\
                 BOX_State[i-1]+BOX_State[i+1]+\
                
BOX_State[i+11]+BOX_State[i+10]+BOX_State[i+9]

Just to explain my plan a little bit: I have two lists, BOX_List and
BOX_State. BOX_State is my way to sidestep the wrappping problem. I
expected an exception with the last number in the list, but not 10
numbers before. As I see it, the problem comes when 'i' reaches
BOX_State[i-1] Is this correct?

And again if you see something that should be different please let me
know, in this way I can improve a little bit every time.

Since there has been some talk about the list itself, when some of you
reply to my posts sometimes I get a mail straight to my account. This
is very useful because it lets me see the reply before it is posted on
the list and because in this way is easier to keep track of the info
that is useful for me. The question is: is this a personal option from
the person who replys? I would like to have all my answers this way, is
it possible?

Thanks a lot for your help.

Happy coding,
Carlos




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


Re: [Tutor] First realscript + Game of Life

2006-11-09 Thread Carlos
Hi,

> What?
> I think you're talking to someone else here, cause I have no idea what 
> you mean.
> Copy binary numbers from memory?
> You mean from any arbitrary memory location you want?
> That sounds a lot like C++ pointers to me. 

That was based on this:

> Hi Carlos,
> I hope this module would help you with the binary conversion part:
>
> 
> def tobits(inte,size = 3):
> """Copy an integer's bits from memory"""
> s=''
> for i in range(size):
> s += str((inte & (1<>i)
> #bits are extracted right-to-left
> s = s[::-1] #reverse the result string
> print s
> return list(s)
> 
>
> 
>   
>>>> >>>test = tobits(30,8)
>>>> 
> 0000
>   
>>>> >>>test
>>>> 
> ['0', '0', '0', '1', '1', '1', '1', '0']
> 
>
> Cheers,
> Rooy
But probably (surely) my interpretation is wrong. Hehe

And about:
> 89+11 = 100, which is longer than the list.

:-[  

Thanks Luke.

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


[Tutor] Angles

2006-11-28 Thread Carlos
Hello to All:

I'm trying to write a sun positioning system with the help of python. 
The idea is that you give the program a location, date and hour and it 
returns the position of the sun.

I found a webpage that details the math behind this 
(http://www.usc.edu/dept/architecture/mbs/tools/vrsolar/Help/solar_concepts.html)
 
, it was fairly trivial to translate this to python until I got to the 
azimuth equation. It looks like this:

x_azm   = sin(hour_R) * cos(decl_R)
y_azm   = (-(cos(hour_R))*cos(decl_R)*sin(lat_R))+(cos(lat_R)* sin(decl_R))
azimuth = atan(x_azm/y_azm)*TODEGREE

where:

Alt = Altitude
Azm = Azimuth
Decl= Declination
HAngle  = Hour angle
alt_R   = Altitude in radians
azm_R   = Azimuth in radians
lat_R   = Latitude in radians
hour_R  = Hour angle in radians
x_azm   = x component of azimuth
y_azm   = y component of azimuth
TODEGREE= Constant equal to 180/p

My python code for this particular equation:

from math import *

def Az(Lat, Dec, H_Ang):

lat_r = radians(Lat)
decl_r = radians(Dec)
hour_r  = radians(H_Ang)

x_azm = sin(hour_r) * cos(decl_r)
y_azm = (-(cos(hour_r)) * cos(decl_r) * sin(lat_r)) + 
(cos(lat_r) *  sin(decl_r))

Azimuth= degrees(atan(x_azm/y_azm))
Azimuth = Azimuth *(-1)
return Azimuth

I was never very good at trigonometry, but looks like my translation of 
the equation is ok and the problem is some kind of python behavior, 
because whenever the results exceed 100° (deg) Python returns the 
complementary angle, it is possible to avoid this? Or I'm overlooking 
somethig?

You can check this by yourself:

If you use Az(34, -21.67, -150) you will get 72.79, the result in the 
webpage tool will be 107.21. And 72.79 + 107.21 = 180
but if you use Az(34, -21.67, -150) you will get 54.88 in both, my 
script and the webpage tool.

If you want to take a look at the webpage tool this is the link: 
http://www.usc.edu/dept/architecture/mbs/tools/vrsolar/frameset.html

Thanks in advance for your help,
Carlos
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Angles

2006-11-29 Thread Carlos
Thanks Terry and Roel,

I got it working now, the problem was a sign situation. I fixed it this way:


from math import *

def Az(Lat, Dec, H_Ang):

lat_R = radians(Lat)
decl_R = radians(Dec)
hour_R  = radians(H_Ang)

x_azm = sin(hour_R) * cos(decl_R)
y_azm = (-(cos(hour_R))*cos(decl_R)*sin(lat_R))+(cos(lat_R)* 
sin(decl_R))

if Lat > 0:
y_azm = y_azm * -1
   
Azimuth = degrees(atan2(x_azm, y_azm)) 
return Azimuth

The if conditional tells the system wether the sun is east or west. 
Looks like this fixes it.

Cheers


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


[Tutor] Sun Location System

2006-11-29 Thread Carlos
Hi Again,

I have been working in a sun location system and it seems like is 
working now. But I have two issues that I hope you can help me solve.

I have a number of functions in this script and I would like to know 
which is the best way to pass values among them? Here is the script so far:

#
from math import *

# I would like to substitute Lat for the location name
def Sol_Pos (Lat, Month, Day, Hour):

month_index = Month -1
date_index = Day -1

def J_Day(month_index,date_index):
j_day=0
date_val=date_index+1
if (month_index==0):
j_day = 0+date_val
elif (month_index==1):
j_day=31+date_val
elif (month_index==2):
j_day=59+date_val
elif (month_index==3):
j_day=90+date_val
elif (month_index==4):
j_day=120+date_val
elif (month_index==5):
j_day=151+date_val
elif (month_index==6):
j_day=181+date_val
elif (month_index==7):
j_day=212+date_val
elif (month_index==8):
j_day=243+date_val
elif (month_index==9):
j_day=273+date_val
elif (month_index==10):
j_day=304+date_val
elif (month_index==11):
j_day=334+date_val
return j_day

 
def Dec(J_Day):

Dec = 23.45 * sin(radians(( j_day + 284.0) * 360/365))
return Dec

def H_Ang(Hour):

Hour_Angle = 15*(12-Hour)
return Hour_Angle

def Alt(Lat, Dec, H_Ang):

lat_r = radians(Lat)
decl_r = radians(Dec)
hour_r  = radians(H_Ang)

sin_alt_r = 
cos(lat_r)*cos(decl_r)*cos(hour_r)+sin(lat_r)*sin(decl_r)
sin2alt   = sin_alt_r * sin_alt_r
cos_alt_r = sqrt(1 - sin2alt)

Alt = degrees(atan(sin_alt_r / cos_alt_r))
return Sol_Alt

   def Az(Lat, Dec, H_Ang):

lat_R = radians(Lat)
decl_R = radians(Dec)
hour_R = radians(H_Ang)

x_azm = sin(hour_R) * cos(decl_R)
y_azm = (-(cos(hour_R))*cos(decl_R)*sin(lat_R))+(cos(lat_R)* 
sin(decl_R))

if Lat > 0:
y_azm = y_azm * -1
   
Azimuth = degrees(atan2(x_azm, y_azm)) 
return Azimuth



And my idea is to give the script a location name, date and hour and it 
will return the sun position relative to that info. So how can I work 
with info of this type?

30.30 48.20 Abadan, Iran
45.40 -98.40 Aberdeen Ap, South Dakota - USA
57.10 -2.10 Aberdeen, Scotland
46.90 -123.80 Aberdeen, Washington - USA
5.30 -4.00 Abidjan, Ivory Coasti
32.40 -99.60 Abilene Ap, Texas - USA
5.50 -0.20 Accra, Ghana

I know that a dictionary probably is a solution, but as you can imagine 
formatting this data is going to take a long time, there are too many 
locations. Is there a solution for this problem?

Thanks for your help,
Carlos
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How many times X is in a list?

2006-12-20 Thread Carlos
Hello,

Can you help me with this please?

I have a list that contains elements to be created (in a 3D app), in the 
list each element is a dictionary that contains data, like:

Elements = [
{'Width': 3.0, 'Depth': 3.0, 'Name': 'Access', 'Parent': 
'Plot', 'Height': 3.0},
{'Width': 3.0, 'Depth': 3.0, 'Name': 'Circulation_01', 
'Parent': 'Access', 'Height': 3.0},
{'Width': 3.0, 'Depth': 3.0, 'Name': 'Circulation_02', 
'Parent': 'Access', 'Height': 3.0},
{'Width': 3.0, 'Depth': 3.0, 'Name': 'Circulation_03', 
'Parent': 'Access', 'Height': 3.0},
{'Width': 2.0, 'Depth': 6.0, 'Name': 'Int_Circ_01', 
'Parent': 'Circulation_01', 'Height': 3.0},
{'Width': 2.0, 'Depth': 5.0, 'Name': 'Int_Circ_02', 
'Parent': 'Circulation_01', 'Height': 3.0},
{'Width': 2.0, 'Depth': 6.5, 'Name': 'Int_Circ_03', 
'Parent': 'Circulation_02', 'Height': 3.0},
{'Width': 2.0, 'Depth': 5.0, 'Name': 'Int_Circ_04', 
'Parent': 'Circulation_02', 'Height': 3.0},
{'Width': 2.0, 'Depth': 5.0, 'Name': 'Int_Circ_05', 
'Parent': 'Circulation_03', 'Height': 3.0},
{'Width': 2.0, 'Depth': 5.0, 'Name': 'Int_Circ_06', 
'Parent': 'Circulation_03', 'Height': 3.0},
  ]

so a for loop is used to iterate the list, like:

for element in elements:
create object with the desired width, depth, name, etc

The thing is that there can only be a "Circulation" by story, so I am 
thinking in adding each created object to a built_Objects list and 
appending the created object to the list, like:

for element in elements:
create element
append element['Name'] to built_Objects

My question is, how can I check how many times "Circulation" appears in 
the built_Objects list? I think that if I get the number of times /N/ 
that "Circulation" appears I can multiply the next circulation elevation 
/N/ times and avoid having two circulations in the same level. Is this a 
correct reasoning?

I did a little research and found that count could help me, so I tried:

print Built_Elements.count('Circulation')

but well is not working. The result is 0, I guess that count is looking 
for the exact term and not something similar

If you know the solution or a better way to do this please let me know.

Thanks in advance,
Carlos




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


Re: [Tutor] How many times X is in a list?

2006-12-20 Thread Carlos

Thanks Kent,

That solves it pretty well.

Carlos



Kent Johnson wrote:
> Yes, count() is looking for exact matches. You can make a new list 
> with just the circulation names and take the length of that; something 
> like this:
> len([name for name in built_Objects if name.startswith('Circulation')])
>
> or perhaps slightly more efficient (Python 2.5):
> sum(1 for name in built_Objects if name.startswith('Circulation'))
>
> Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Project Review

2006-12-21 Thread Carlos
Hello,

I have been working in a script for my master thesis project (M Arch) 
and since this is the first project that I do in this way, I would like 
to know if someone here would be interested in taking a look at what I 
have done so far. My impression is that since I have been learning on my 
own, I am doing stuff probably not in the best way. The idea is that 
someone who really knows about programming can take a look and give me 
some advice to correct the points that are not so good in my code.

I don't know if this is a good thing to ask in this mailing list, or if 
it is possible for someone to take a look and spot my errors, but I 
really can't think of a better way.

Best regards,
Carlos
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Project Review

2006-12-21 Thread Carlos
Kent,

Yes it is a little longer than that, let me see how can I make it more 
compact and will get back to the list with a URL.

Thanks!!!
Carlos

Kent Johnson wrote:
> Carlos wrote:
>> Hello,
>>
>> I have been working in a script for my master thesis project (M Arch) 
>> and since this is the first project that I do in this way, I would 
>> like to know if someone here would be interested in taking a look at 
>> what I have done so far. My impression is that since I have been 
>> learning on my own, I am doing stuff probably not in the best way. 
>> The idea is that someone who really knows about programming can take 
>> a look and give me some advice to correct the points that are not so 
>> good in my code.
>>
>> I don't know if this is a good thing to ask in this mailing list, or 
>> if it is possible for someone to take a look and spot my errors, but 
>> I really can't think of a better way.
>
> If it is a short script you can just include it in an email to the 
> list. Longer than 50-100 lines is probably too long for mail. In this 
> case the best thing is to put the script on a web site and post the 
> URL to the list.
>
> Kent
>
>

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


Re: [Tutor] Tutor Digest, Vol 34, Issue 42

2006-12-21 Thread Carlos

Chis,

In the past  I have received very valuable info from other list users, 
that has helped me to solve problems that I had. Just yesterday Kent 
helped me with something very specific.


I'm asking for a project review because my code is working now, it is 
not complete but it is working. What I need is not a specific solution, 
but more something like a general review of the code. Because while 
probably everything is working, there might be very evident problems 
that are general in nature and that are impossible for me to spot for a 
number of reasons.


What is this project about? Well I'm allways a little bit afraid to 
speak about that, because after 30 seconds most of the people just wants 
to get away as fast as possible. But hey, you asked for it :-)


My project is a building prototyping system, my idea is that it is 
possible to investigate different spatial configurations for an 
anchitectural project, for you to have a better idea, let me show a 
simplified step list:


1. - Locate the plot that contains the architectural project. Details 
like orientation, latitude and longitude are relevant.




2. - Generate the collection of spaces that compose the project. Details 
like size and position respect to other spaces are relevant.




3. - Analyze the collection of spaces. This is an intermediate step, and 
its function is that the system knows the details of the given data.




4. - Run the system. Based on a Genetic Algorithm, the system generates 
a population of possible solutions and evaluates how well they perform 
to give at the end a number of solutions that represent possible 
projects. For the first version of the system the evaluated 
considerations are going to be kept at a minimum, with the intention of 
simplifying the development process. Those considerations are going to 
be on the one hand, proximity that is expressed in the schematic design. 
And on the other hand an external evolutionary pressure, in this case 
sun incidence. Further versions of the system are intended to cover more 
aspects of an architectural project.


If you, besides python, know something about Maya (the 3D App) that 
would just be great for me. I have spent the last semester learning 
python and mel the scripting language of maya. Thankfuly I found 
something called cgkit, that has let me use python inside of maya.


And if by chance you are familiar with genetic algorithms, well that 
would be perfect, because you can take a look at how I took a genetic 
algorithm python module and applied to my project.


But in the case that you are not familiar with maya or genetic 
algorithms, well the code is still python and I bet that a veteran like 
you can spot a bunch of things that could be done better, at the big 
scale of the code workings or a the small one of specific stuff.


MArch as far as I know is not something cryptic, it stands for Master of 
Architecture and it follows the normal master courses notation. You can 
check it here 
<http://en.wikipedia.org/wiki/Master%27s_degree#MArch_I..2C_MArch_II.>.


Just to clarify :-)

Cheers
Carlos

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


[Tutor] Lists on the fly?

2006-12-22 Thread Carlos
Hello,

I am wondering if it is possible to create lists on the fly. The script 
that I'm working on needs a number of parameters, one of those is 
population, and this corresponds to the number of solutions that a 
genetic algorithm generates on each generation (iteration). The thing is 
that I need to generate one list for each population member and then 
append the corresponding population members to that particular list.

This is only so you can have an idea:

for i in range(5):
'list_%i' % (i) = []

or:

for i in range(5):
lista_+'%i' % (i) = []

:-[

Is this possible?

Thanks in advance,
And Merry Christmas,
Carlos


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


Re: [Tutor] Lists on the fly?

2006-12-22 Thread Carlos

Kent,

Thanks a lot, that solves it... again

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


Re: [Tutor] Lists on the fly?

2006-12-23 Thread Carlos
Hi,

First of all, thanks for your help.

This is how this ended up:

Elements =  [
{'Name': 'Access', 'Parent': 'Plot', 
'Level': 1.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Circulation_01', 'Parent': 
'Access', 'Level': 1.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Circulation_02', 'Parent': 
'Access', 'Level': 2.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Circulation_03', 'Parent': 
'Access', 'Level': 3.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Int_Circ_01', 'Parent': 
'Circulation_01', 'Level': 1.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Int_Circ_02', 'Parent': 
'Circulation_01', 'Level': 1.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Int_Circ_03', 'Parent': 
'Circulation_02', 'Level': 2.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Int_Circ_04', 'Parent': 
'Circulation_02', 'Level': 2.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Int_Circ_05', 'Parent': 
'Circulation_03', 'Level': 3.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Int_Circ_06', 'Parent': 
'Circulation_03', 'Level': 3.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0}
   ]

# Get Levels List 
for Element in Elements:
Lev_List['Level_%i' % (Element['Level'])] = []

# Append Element to corresponding Level
for Element in Elements:
Lev_List['Level_%i' % (Element['Level'])].append(Element['Name'])

print Lev_List

And this is the result:

Lev_List = {
 'Level_1': ['Access', 'Circulation_01', 
'Int_Circ_01', 'Int_Circ_02'],
 'Level_2': ['Circulation_02', 'Int_Circ_03', 
'Int_Circ_04'],
 'Level_3': ['Circulation_03', 'Int_Circ_05', 
'Int_Circ_06']
}

It works fine, as far as I can tell. I mean, no matter how many 'Levels' 
it will allways get them right (levels so far are only integers). 
Probably the first loop is a little redundant, but performance is not 
one of my concerns now, but in the future the project will not be 
composed by a handful of spaces, probably by hundreds or more.

Regards,
Carlos






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


[Tutor] Why a global?

2006-12-27 Thread Carlos
Hello,

Can help me with this:

I am using a python module that someone else wrote 
http://www.alextreme.org/projects/python_ai/

This is an example of how it works

# Usage:
# import ga
#
# ga = ga.GA()
# ga.evolve()

# Function arguments (fun defaults are used otherwise):
#
# ga.GA(population_size, gene_size, crossover_rate, mutation_rate, 
list_of_alleles)
# ga.evolve(number_of_generations_to_process)
#
# ga.set_fitness(your_fitness_function)

# Interesting public variables (besides the ones you can modify using arguments)
#
# ga.debug = 1   (turns on lots of output)
# ga.halt  = X.X (stop if this fitness is reached)

# Note: crossover_rate is the chance two entities will reproduce
#   mutation_rate is the chance a single entity will have an
allele changed

My problem is that no matter were I put this, I have to declare ga a 
global. So I ended up with this:

def runGA(Pop, Gen, It):

# Declare a Global. This is the only solution for now
global ga

# Set the arguments of the GA   
ga = ga.GA(pop = 2, alleles = range(10), gene_size = 8)
ga.debug = 1
ga.echo_entities()

Can you help me with this information? or what else is needed for you to 
help me solve this problem?

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


Re: [Tutor] Why a global?

2006-12-28 Thread Carlos
Chris,

Sheesh, that solved it, guess that I got to learn OO next. Unles it is 
not related... :-[

Thanks a lot!
Carlos
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Encoding and Decoding

2007-01-02 Thread Carlos
Hello,

I have been having problems to solve a situation in which I need to 
encode and decode information, hope that someone can give me a hand. The 
solution for this problem has gone thru many iterations, but I recently 
found that the long (for me) is the only one.

As you might remember Im working with some elements, for example:

ELEMENTS = [{'Name': 'Access', 'Parent': 'Plot', 'Level': 1.0, 'Height': 
3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Circulation_01', 'Parent': 
'Access', 'Level': 1.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Circulation_02', 'Parent': 
'Access', 'Level': 2.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Circulation_03', 'Parent': 
'Access', 'Level': 3.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Int_Circ_01', 'Parent': 
'Circulation_01', 'Level': 1.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Int_Circ_02', 'Parent': 
'Circulation_01', 'Level': 1.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Int_Circ_03', 'Parent': 
'Circulation_02', 'Level': 2.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Int_Circ_04', 'Parent': 
'Circulation_02', 'Level': 2.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Int_Circ_05', 'Parent': 
'Circulation_03', 'Level': 3.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0},
{'Name': 'Int_Circ_06', 'Parent': 
'Circulation_03', 'Level': 3.0, 'Height': 3.0, 'Width': 3.0, 'Depth': 3.0}
 ]

The genetic algorithm that Im using (GA) generates solutions for a given 
problem, expressed in a list, this list is composed by integers. Every 
element in the list takes 8 integers, is a little messy but this is because

List [0] = Tens X position
List [1] = Units X position
List [2] = Decimals X position
List [3] = If < than 5 the number is negative, else is positive

Then if the result is List = [6, 1, 2, 3] the X position equals -612.3. 
This is the same for the Y position. If there are 10 elements the list 
is going to be 80 integers long and if there are 100 elements, well you 
get a very long list...

With this in mind my question would be, how can I keep track of this 
information? I mean how can I assign this List positions to each 
element? This is needed because this is going to be a long list and the 
GA needs to evaluate the position of each element with respect to the 
position of the other elements. So it needs to know that certain numbers 
are related to certain element and it needs to have access to the size, 
level, name and parent information... I hope that this is clear enough.

Thanks in advance,
Carlos






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


Re: [Tutor] Encoding and Decoding

2007-01-02 Thread Carlos
Hi Kent,

I have yet to get into OO, and the GA that I'm using was done in this 
way, so I can't mess with it that much. So for now yes, the list has to 
be a flat element containing all this info.

I have been reading about OO lately and a element class seems to be a 
good idea, I'm working on it now, but I still don't get OO very well. My 
initial idea is that a loop could iterate over the element list and 
create objects with the needed parameters and hooks to the list that 
link to the correct list locations.

Could you elaborate on the converters and the class that wraps the list???

Thanks




Kent Johnson wrote:
> I will assume there is a good reason for storing the coordinates in 
> this form...
>
> Do the numbers have to be all in a single list? I would start by 
> breaking it up into lists of four, so if you have 10 elements you 
> would have a list of 20 small lists. It might make sense to pair the x 
> and y lists so you have a list of 10 lists of 2 lists of 4 numbers, e.g.
> [ [ [6, 1, 2, 3], [7, 2, 8, 4] ], ...]
>
> Another thing to consider is whether you might want to make a class to 
> hold the coordinate values, then you could refer to x.tens, x.units, 
> x.decimal, x.sign by name.
>
> If you need a single list for the GA to work, one alternative would be 
> to make converters between the nested representation and the flat one. 
> Alternately you could wrap the list in a class which provides helpful 
> accessors.
>
> HTH
> Kent
>
>

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


Re: [Tutor] Encoding and Decoding

2007-01-02 Thread Carlos

Kent,

Will give this a try.

Thanks for your help,
Carlos


Kent Johnson wrote:
> OK, off the top of my head (not tested) here are some things to get 
> you started.
>
> You could write a function that would retrieve a coordinate value 
> given an index number, for example:
> def getCoord(data, ix):
>   base = ix*4
>   value = data[ix]*10 + data[ix+1] + data[ix+2]/10.0
>   if data[ix+3] < 5:
> value = -value
>   return value
>
> Now if data is your big list, you can write getCoord(data, 5) to get 
> the value stored at data[20] to data[23]. Similarly you could write a 
> setter and maybe a getXY() function that returns a pair (x, y). So 
> that is a place to start.
>
> If you want to avoid passing the list around it might make sense to 
> make a class to hold it. Then you would have something like
> class Data(object):
>   def __init__(self, lst):
> self.data = lst
>
>   def getCoord(self, ix):
> base = ix*4
> value = self.data[ix]*10 + self.data[ix+1] + self.data[ix+2]/10.0
> if self.data[ix+3] < 5:
>   value = -value
> return value
>
> Now you can create a Data object from a list of values and ask it for 
> values:
> d = Data()
> d.getCoord(5)
>
> I'm not sure this is much improvement over passing around the list, 
> actually; you still have to pass around the Data object...it might 
> just be a matter of taste.
>
> HTH,
> Kent

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


[Tutor] Image Question, List of Image Colors

2007-01-11 Thread Carlos
Hello,

Could someone who is familiar with image manipulation tell me what is 
the best way to obtain the list of colors inside an image?

By best I'm referring to something that gets the job done in the fastest 
way, because this operation will be repeated a number of times.

Thanks for your help,
Carlos

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


Re: [Tutor] Image Question, List of Image Colors

2007-01-11 Thread Carlos
Hello,

I'm trying to do what Kent suggested, but I have a little problem, no 
matter were I put my image or if I use sys.path.append to append the 
folder were my Image is located it is impossible to open the image. I 
know that this is a silly question but what is going on?

I like to solve problems but this is... well. I searched the web for 
help, but nothing.

This is how I am doing it

from PIL import Image
import sys

sys.path.append('D:\MASTER THESIS\Branch_01\Thesis B_01\images\tmp')
im = Image.open("Wind_Test_01")

Thanks and sorry for bothering you with such a basic thing
Carlos
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Image Question, List of Image Colors

2007-01-11 Thread Carlos
Hello,

Well seems like Danny was right, the backslashes were the problem! This 
really got an 11 in my frustration meter.

Thanks for your help
Carlos

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


[Tutor] Problems with a Class

2007-01-12 Thread Carlos
Hello,

I'm just about to finish my project, but something is causing me 
trouble. I need to find out how to get some information out of the 
genetic algorithm that Im using. This algorithm is generating some 
coordinates for a collection of objects, until now I needed only the 
final result of the process. But I discovered that the final information 
is not enough, I need to get some intermediate data to actualize the 
positions of the objects and then evaluate those positions.

This is the area of the algorith that I think holds the info that I need:

def evolve(self, generations = 100):
  
self.halt_reached = 0
   
for gen in range(generations):

#Changed.
print 'GEN:',gen, self.entities
   
self.do_mutation()
self.do_crossover()
print "Average fitness generation " + str(gen) + ": " + 
str(self.avg_fitness())
if self.debug == 1:
self.echo_fitness()
if self.halt >= 0:
max_entity = self.get_max_fitness()
fit = self.calc_fitness(max_entity)
if fit >= halt:
self.halt_reached = 1
return [max_entity]

The line marked as #Changed is what I changed,  with this I was able to 
print the info, but I'm sorry to say that I have no clue at how to apply 
something like return() that would give me this self.entities list. As 
you can see there is a for loop and I need the info every time that it 
gets updated by the loop.

Hopefully I'm making myself clear and the info is enough.

Thanks for your help in advance
Carlos


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


Re: [Tutor] Problems with a Class

2007-01-12 Thread Carlos
Hi,

Just in case that the info that I provided is not enough, I posted the 
code in a python forum, hope that somebody can take a look.

http://python-forum.org/py/viewtopic.php?p=11063#11063

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


Re: [Tutor] Tutor Digest, Vol 35, Issue 38

2007-01-13 Thread Carlos

Hello,

> Unfortunately, no. I for one can't interpret "I need the info every 
> time that it gets updated by the loop"
The GA is creating solutions for a given problem, that are contained in 
self.entities that looks like this:

Generation_01: [[1, 0, 0, 1, 0, 1, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0, 
0, 0], [1, 1, 0, 0, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 0, 0, 1, 0, 1], 
[1, 0, 1, 0, 1, 0, 1, 1, 0, 1]]
Generation_02, Generation_03, Generation_04...
Generation_25:[[1, 1, 1, 1, 1, 1, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 
1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]

self.entities gets new values with each generation, because the solution 
to a given problem is evolving and getting closer to a correct result. 
The problem is that with:

 Phenotypes = ga_inst.evolve(Gen)

I only get the last generation -or iteration- and I need to actualize 
some objects position before evaluating the generation, so what I need 
is to get the values of self.entity on each generation. Since this 
values are going to be evaluted, I need to actualize some gemetrical 
objects with every new self.entities before evaluating the solution.

I tried this:

def evolve(self, generations = 100):
""" Process a number of generations
Stop if:
- number of generations = generations
- halt variable has been set AND
  there is an entity with a fitness which has obtained or exceeded
  the halt value
Return the list of entities, or the halt-entity if prematurely 
halted
  """
   
self.halt_reached = 0
   
for gen in range(generations):

print 'TEST', self.entities ### THIS IS MY CHANGE


self.do_mutation()
self.do_crossover()
print "Average fitness generation " + str(gen) + ": " + 
str(self.avg_fitness())
if self.debug == 1:
self.echo_fitness()
if self.halt >= 0:
max_entity = self.get_max_fitness()
fit = self.calc_fitness(max_entity)
if fit >= halt:
self.halt_reached = 1
return [max_entity]
   
return self.entities

I can actually print the self.entities list once for each iteration, 
before the evaluation takes place. What I dont know is how to actually 
do something with the list, like putting it in a variable or something 
to get access to it and actualize the geometry of my project. So 
basically if there are 100 iterations I would need a way to get this 
list 100 times, one for each iteration with its new data.

And just in case that it helps, the address of the forum were I uploaded 
a piece of the code:

http://python-forum.org/py/viewtopic.php?p=11063#11063

And the GA project page:

Genetic Algorithm Python module
http://www.alextreme.org/projects/python_ai/

If you can help me please do it, this is critical for my project :(

Thanks for helping
Carlos

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


Re: [Tutor] Problems with a Class

2007-01-13 Thread Carlos
Hello Again,

Looks like Im getting there now. I did this inside the GA module:

def update(self):

return self.entities

now Im putting it in my code:

def my_fitness(entity):
x = ga.update()
print 'X', x
fitness = 0.0
for i in entity:
if i == 1:
fitness += 1.0
return fitness

This fitness fuction sets the evaluation criteria. I does the job, but 
there is a small problem, it returns too much information! for example 
in generation 1 it gives:

X [[0, 0, 1, 1, 0, 1, 1, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [1, 0, 0, 0, 
1, 1, 0, 0, 0, 0]]
X [[0, 0, 1, 1, 0, 1, 1, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [1, 0, 0, 0, 
1, 1, 0, 0, 0, 0]]
X [[0, 0, 1, 1, 0, 1, 1, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [1, 0, 0, 0, 
1, 1, 0, 0, 0, 0]]
X [[0, 0, 1, 1, 0, 1, 1, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [1, 0, 0, 0, 
1, 1, 0, 0, 0, 0]]
X [[0, 0, 1, 1, 0, 1, 1, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [1, 0, 0, 0, 
1, 1, 0, 0, 0, 0]]

and in generation 2:

X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 
0, 1, 1, 0, 0, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [1, 0, 0, 0, 
1, 1, 0, 1, 1, 0]]
X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 
1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [1, 0, 0, 0, 
1, 1, 0, 1, 1,

[Tutor] Clustering?

2007-01-16 Thread Carlos
Hello to everybody,

I have a question that I think is a little related to clustering, I have 
a list of lists, like this:

List = [[1,5],[6,8],[48,10],[99,56]]

The list is composed by a large number of lists not just four, and each 
'interior' list contains two numbers that are the location of an object 
in a plane, so they are X and Y coordinates, my question is:

Can I use this list to evaluate how many points are in a given range? 
Thats is taking the highest and lowest values for X an Y and, lets say 
divide that range in 10 regions, then get the number of objects on each 
region. Is this possible? and if yes, how canI do it? I ask this because 
as you know my python skills are not that great :)

Thanks in advance for your help,
Carlos

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


Re: [Tutor] Clustering?

2007-01-16 Thread Carlos

Hallo ,

Andre thanks a lot for your help, seems to me like  my script can work 
with your function.

I found this searching the internet:

cluster 1.1.1b2
python-cluster is a "simple" package that allows to create several 
groups (clusters) of objects from a list

>>> from cluster import *
>>> data = [12,34,23,32,46,96,13]
>>> cl = HierarchicalClustering(data, lambda x,y: abs(x-y))
>>> cl.getlevel(10) # get clusters of items closer than 10
[96, 46, [12, 13, 23, 34, 32]]
>>> cl.getlevel(5)  # get clusters of items closer than 5
[96, 46, [12, 13], 23, [34, 32]]


I would like to give it a try because I have the impression that it can 
be helpful too. My problem now is the lambda function, I was wondering 
if someone could be so kind as to give me an example that could work in 
my list with nested tuples.

Thanks again!
Carlos



Andre Engels wrote:
> 2007/1/16, Carlos <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>:
>
> Hello to everybody,
>
> I have a question that I think is a little related to clustering,
> I have
> a list of lists, like this:
>
> List = [[1,5],[6,8],[48,10],[99,56]]
>
> The list is composed by a large number of lists not just four, and
> each
> 'interior' list contains two numbers that are the location of an
> object
> in a plane, so they are X and Y coordinates, my question is:
>
> Can I use this list to evaluate how many points are in a given range?
> Thats is taking the highest and lowest values for X an Y and, lets say
> divide that range in 10 regions, then get the number of objects on
> each
> region. Is this possible? and if yes, how canI do it? I ask this
> because
> as you know my python skills are not that great :)
>
>
> First, this feels like a list of tuples rather than a list of lists; 
> however, tuples and lists don't differ that much in their behaviour, 
> so there's nothing really lost.
>
> And yes, it is possible. An inline if would be the way I would resolve 
> that:
>
> def withinrange(list,xmin,xmax,ymin,ymax):
> # Get the elements of list for which the first part of the pair is 
> between xmin and xmax
> # (inclusive) and the second between ymin and ymax.
> return [c for c in list if xmin <= c[0] <= xmax and ymin <= c[1] 
> <= ymax]
>
> The longer but clearer method of doing the same would be:
>
> def withinrange(list,xmin,xmax,ymin,ymax):
> templist = []
> for c in list:
> if xmin <= c[0] <= xmax and ymin <= c[1] <= ymax:
> templist.append(c)
> return templist
>
> -- 
> Andre Engels, [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> ICQ: 6260644  --  Skype: a_engels
> 
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.432 / Virus Database: 268.16.12/630 - Release Date: 1/15/2007 
> 8:28 PM
>   

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


[Tutor] Thanks

2007-01-23 Thread Carlos
Hello,

I want to thank all you for the all help that you have been lending to 
me for the past months.  My masters thesis is now finished and I have to 
say that it has been very succesfull. This is something that would have 
been impossible if not for all the help that you gave to me. I was 
thinking in mentioning those of you who helped me, but really fear to 
miss someone, so thanks to all of you who contributed. Thank you very much.

This doesnt means that you will get rid of me, I want to get into OO 
now.  :)

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


Re: [Tutor] web-based python?

2010-08-02 Thread Carlos Guerrero
-terms tutorial would be a wonderful thing
> to
> have.  As you said before, web programming is a lot more involved than
> desktop programming.  I think it would be really a fun challenge to put
> together a great soup-to-nuts tutorial on this (but I am far from the one
> to do it!), since it incorporates so many elements.  I wish you luck on
> the Py3 tutorial and and web app tutorial work when you have the chance.
>
> Thanks,
> Che
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


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


[Tutor] Pastebin.com fork based completely on Python (Django)

2010-09-07 Thread Carlos Guerrero
I did a "pastebin.com" fork in Django (python web framework) if anyone
interested on join using it or improving it, can find the code at:
http://gitorious.org/aprendiendo-django/aprendiendo-django

Also see it working at http://notas.canaima.softwarelibre.gob.ve/

Best Regards

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


Re: [Tutor] Best Python Editor

2009-06-14 Thread Carlos Zuniga
On Sat, Jun 13, 2009 at 7:57 PM, Wayne wrote:
> On Sat, Jun 13, 2009 at 7:40 PM, Mike Hoy  wrote:
>>
>> Try out Vim. It may take you a week to get used to it. Best thing I ever
>> did was finally get started on Vim. Once I got used to it I was very happy.
>> Google around for Vim tutorials. There is a #VIM channel on freenode I
>> believe. There is also a VIM mailing list that is very helpful. You won't
>> need these for long. Once you get used to it and think you've learned all
>> you can you find out there's even more stuff you can do with it.
>> 
>>
>> So it's something that you use for life once you get that feeling of
>> enlightenment that comes from never having to remove your hands from the
>> keyboard.
>
> I'm another viim fanatic;
>
> I use two terminals - one with vim and one with ipython (I write most of my
> code on linux). When I'm on windows I have a cmd window open with Ipython
> and I have a gVim window open. I'm sure I barely scratch the surface of
> things I can do and I know I've stopped using some things that I'm sure I'll
> start using the more I code.
>
> I really like using F5 to run my code, so you can put in your .vimrc so you
> don't have to type it, or just type it every time:
>
> map  :!python %
>
> and every time you hit  it will run your current script.
>
> Of course I also write code in c++ for school, so I have a few different
> keys that will change the F5 bindings.

You can map it directly to the filename extension so it uses the
correct bindings automatically

au BufNewFile,BufRead *.py map  :!python %

Cheers

-- 
Linux Registered User # 386081
A menudo unas pocas horas de "Prueba y error" podrán ahorrarte minutos
de leer manuales.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2009-11-16 Thread Carlos Flores

Dear Python,

I am trying to learn Python to experience my
computer programming knowledge. I am working through the online
textbook How to Think Like A Computer Scientist. I have made it through
chapters 1-5 and completed the exercises at the end. Now I am on
chapter 6 and I am having a lot of trouble and its only going to get
harder from here on. Is there any sources that help with these
exercises that are at the end of each chapter? Its tough not knowing if
I am doing these exercises correctly without seeing the actual answers.


Thanks. 
  
_
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/171222986/direct/01/___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Quick question,

2006-04-07 Thread Carlos Benevides
Hi,

Can someone tell me what the r before the expression means, as in 
"re.compile(r'(\.exe|\.zip|\.pif|\.scr|\.ps|\.pdf|\.ppt)$')"?

I've seen regular expressions both ways, and I've seen them work with or 
without the r.  Just wondering what it does, or if it makes a difference.

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


[Tutor] String question.

2006-04-12 Thread Carlos Benevides
All,

I have a problem/question I'd like to pose to you guys on how best to 
accomplish the following.  I have a string that will vary in size, what 
I would like to do is split into n size chunks.  I am also not sure how 
best to represent the chunks.  For example, say I have a len(s) = 200 
chars.  I'd like to get one chunk with 160 of those chars and the 
remaining 40 in a second.  Likewise, if I have a len(s) = 350, I'd like 
two chunks of 160 and a 3rd with the remainder.

I don't know what it would best way to accomplish this.  I have the idea 
of converting the string to a list of chars loop through it until size 
is met, create a new string with s=s[:160], then start again, and so 
on.  Is this the only way to accomplish this? Or is there a more 
elegant/clever way?

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


Re: [Tutor] question about looping.

2006-10-06 Thread Carlos Hanson
Doug Potter wrote:
> Hi,
> 
> I at trying to create a bunch of text files in a single directory on a 
> Linux system,
> something like this.
> 
> import os
> 
> routers = ['adnc-6321', 'adnp-2341', 'adnw-2632']
> 
> for i in routers:
> os.system('/bin/touch' %s) % i
> 
> of course this dosn't work.

try using the following:

for i in routers:
os.system('/bin/touch %s' % i)

> Is there a simple way to get this done?

You can also use the builtin file object:

for i in routers:
f = file(i, 'w')
f.close()

> Thanks for your time.
> _______
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Carlos Hanson
Web Specialist
Tigard-Tualatin School District
503.431.4053
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to read content in a tar file with tarfile module

2006-10-10 Thread Carlos Hanson
On Tue, October 10, 2006 11:15 am, Magnus Wirström wrote:
> Hi everyone
>
> I have written a app that makes a tar file and all works well... Now
> i want to expand that app so it can read read the tar and give me the
>  contents of the tar file. How is the best way to do this ? I can't
> find a "listdir" like function in tarfile. Can anyone point me in the
> right direction? Thanks Magnus

There are two choices depending on your needs.  First is the list()
method of a TarFile object:

>>> from tarfile import TarFile
>>> tar = TarFile('files.tar')
>>> tar.list()
-rw-r--r-- chanson/chanson  0 2006-10-10 11:31:08 file.1
-rw-r--r-- chanson/chanson  0 2006-10-10 11:31:11 file.2
-rw-r--r-- chanson/chanson  0 2006-10-10 11:31:15 file.3

The second option is the getmembers() method which returns TarInfo
objects:

>>> members = tar.getmembers()
>>> for member in members:
... print member.name
...
file.1
file.2
file.3
>>> for member in members:
... print "%s %s/%s\t%s %s %s" % (
... member.mode, member.uname, member.gname,
... member.size, member.mtime, member.name)
...
420 chanson/chanson 0 1160505068 file.1
420 chanson/chanson 0 1160505071 file.2
420 chanson/chanson 0 1160505075 file.3


-- 
Carlos Hanson
Web and System Administrator
Tigard-Tualatin School District
503.431.4053


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


Re: [Tutor] I need a time object from the future

2006-10-20 Thread Carlos Hanson


On Fri, October 20, 2006 8:55 am, William O'Higgins Witteman wrote:
> I've been looking into this, and I am not understanding how to get
> this task done.  I need to be able to look at a time object and know
> if it si between now and a set point 120 days in the future.  I can
> get a value for now (currently I am using datetime.datetime.now()),
> but I haven't found a way to get now + 120 days, or figured out how
> to test if a given datetime falls between the two.  Any pointers
> would be appreciated. Thanks. --

The time() function returns the current time in seconds, so one idea
is adding the number of seconds for 120 days:

>>> from time import time, ctime
>>> help(time)
Help on built-in function time:

time(...)
time() -> floating point number

Return the current time in seconds since the Epoch.
Fractions of a second may be present if the system clock provides
them.
>>> t1 = time()
>>> t2 = t1 + 120*24*60*60
>>> now = time()
>>> now > t1 and now < t2
True
>>> ctime(t1)
'Fri Oct 20 09:09:26 2006'
>>> ctime(t2)
'Sat Feb 17 08:09:26 2007'
>>> ctime(now)
'Fri Oct 20 09:10:14 2006'

-- 
Carlos Hanson

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


Re: [Tutor] shebang problem

2006-11-04 Thread Carlos Hanson
On Sat, November 4, 2006 4:11 pm, Brian van den Broek wrote:
> Hi all,
>
> I'm still getting comfortable with Linux and this might be an OS
> rather than a python problem.
>
> I am trying to make a script directly executable. I've reviewed the
> 2nd ed of the Nutshell, and I cannot work out what I'm doing wrong.
> I'm running ubunutu 6.10 (edgy eft). Here's a copy past of my command
> line:
>
> [EMAIL PROTECTED]:~/test$ which python
> /usr/bin/python
> [EMAIL PROTECTED]:~/test$ ls -la shebangtest.py
> -rwxr-xr-- 1 brian brian 68 2006-11-04 02:29 shebangtest.py
> [EMAIL PROTECTED]:~/test$ cat shebangtest.py
> #!/usr/bin/python
>
> if __name__ == '__main__':
>
>  print "It works"
> [EMAIL PROTECTED]:~/test$ shebangtest
> bash: shebangtest: command not found
> [EMAIL PROTECTED]:~/test$ shebangtest.py
> bash: shebangtest.py: command not found
>
> I've also tried:
>
> #!/usr/bin python
>
> as my shebang line.
>
> I've been unable to get this to work. Clearly, there is something I've
> misunderstood. (`#!' is not an easy thing to google for :-)
>
> Best,
>
> Brian vdB
>

Your answer lies in the file permission.  The file needs to be
executable.  If you look at the man pages for chmod, you will find
your answer.

The shebang line tells the shell what to use to run the script.  For
example, if the file is not executable, you would execute it as
follows:

$ python shebangtest.py

As you found with `which python`, python is in /usr/bin, so executing
the script is actually

$ /usr/bin/python shebangtest.py

Therefore, the shebang line needs to be as follows:

#! /usr/bin/python

Then once the script has execute permissions (man chmod), it will run
as expected.

-- 
Carlos Hanson
Web and System Administrator
Tigard-Tualatin School District
503.431.4053


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


Re: [Tutor] shebang problem

2006-11-04 Thread Carlos Hanson
On Sat, November 4, 2006 11:07 am, Jonathon Sisson wrote:
> Brian,
>
> It's not a permissions issue...
>
> (from the original e-mail...see below)
>  >> [EMAIL PROTECTED]:~/test$ ls -la shebangtest.py -rwxr-xr-- 1 brian
>  >> brian 68 2006-11-04 02:29 shebangtest.py
>
> This is clearly executable by brian, and clearly being executed by
> brian.  The shebang line is correct (#!/usr/bin/python).
>
[...]

Good call.  I jumped on the answer without making sure I clearly read
all the information provided.

-- 
Carlos Hanson



>
> Carlos Hanson wrote:
>>
>> Your answer lies in the file permission.  The file needs to be
>> executable.  If you look at the man pages for chmod, you will find
>> your answer.
>>



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


Re: [Tutor] syntax question

2008-05-21 Thread Carlos Hanson
On Wed, May 21, 2008 at 5:27 AM, Eric Abrahamsen <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> This is a syntax that I've seen on occasion in other people's code:
>
> theme = (VALID_THEMES[0], theme) [ theme in VALID_THEMES ]
>
> I have no idea how this works, or how to go about looking it up. Can someone
> enlighten me as to what's happening here?
>
> Many thanks,
> Eric


First, I looked at the code to see what I easily understood:

 - VALID_THEMES is a list of type something, since it has an index
applied to it:VALID_THEMES[0]
 - theme is a type something that is in the list: theme in VALID_THEMES

Next, I started playing with it based on what I knew using string as
the theme type:

--> VALID_THEMES = ['sun', 'moon', 'earth']
--> theme1 = 'moon'
--> theme2 = 'mars'
--> print (VALID_THEMES[0], theme1)
('sun', 'moon')
--> print (VALID_THEMES[0], theme2)
('sun', 'mars')
--> [theme1 in VALID_THEMES]
[True]
--> [theme2 in VALID_THEMES]
[False]
--> (VALID_THEMES[0], theme1)[theme1 in VALID_THEMES]
'moon'
--> (VALID_THEMES[0], theme2)[theme2 in VALID_THEMES]
'sun'

So what just happened? First, we created a tuple of the first
VALID_THEME and a variable theme. Then we tested the variable theme to
see if it was a VALID_THEME. The combination of the two always gives
us a valid theme.

The test if [theme in VALID_THEMES] becomes an index to the tuple:

--> (VALID_THEMES[0], theme1)[1]
'moon'
--> (VALID_THEMES[0], theme1)[0]
'sun'

But we got [True] and [False]:

--> True == 1
True
--> False == 0
True

So in words, the code returns the default theme which is the first in
the list of valid themes unless the chosen theme is also in the list
of valid themes.

My suggestion is to play with code in the interpreter that you don't understand.

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


Re: [Tutor] String Replacement Question

2008-05-21 Thread Carlos Hanson
On Wed, May 21, 2008 at 9:39 AM, Jeff Younker <[EMAIL PROTECTED]> wrote:
> On May 21, 2008, at 6:42 AM, Kinuthia Muchane wrote:
>
>>>>> st = "String"
>>>>> print "%s " %st*3
>>
>> String String String
>>>>>
>>
>> Does this help?
>
> Another approach is to use dictionaries for string
> replacement.
>
>>>> subst = {'some': 'thing'}
>>>> print "%(some)s%(some)s%(some)s"  % subst
> thingthingthing
>

As an alternate to repeating the formated string:

--> print '%(some)s'*3 % subst
thingthingthing

(forgot to reply all)

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


[Tutor] List elements as indices to another list

2008-08-03 Thread Carlos Laviola
Hi,

I have a simple "matrix" (nested list) defined as such:

M = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

I'm trying to come up with a different way of getting its, well,
"reverse antidiagonal", since the actual antidiagonal of M goes from
M[0, N] to M[N, 0] according to
http://planetmath.org/encyclopedia/AntiDiagonalMatrix.html:

j = 0
for i in range(len(M)-1, -1, -1):
print M[i][j]
j += 1

This works fine, but I was looking for a different solution, just for
kicks, and came across something interesting. I can do:

>>> i, j = range(len(M)), range(len(M)-1, -1, -1)
>>> i
[0, 1, 2]
>>> j
[2, 1, 0]

Theoretically, I could then just iterate over range(len(M)) and grab
M[i[N]j[N]], but that's not legal. What would be the right way of doing
this?

Thanks in advance,
Carlos



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


Re: [Tutor] optparse example

2008-09-22 Thread Carlos Hanson
On Mon, Sep 22, 2008 at 7:16 AM, Tasos Latsas <[EMAIL PROTECTED]> wrote:
> Hello list,
> I tried the optparse example from the python library reference and it
> doesn't seem to work..what am I doing wrong?
> I keep getting the "incorrect number of arguments" message although i
> use the correct number..
>
> The example is here :
> http://docs.python.org/lib/optparse-putting-it-all-together.html
>
> if i edit the code and write:
> print parser.parse_args()
>
> I get:
> (, [])
>
> as you can see the argument list is empty
> I run the program as ./parser.py -q
> (i also tried 'python parser.py -q' but didnt help)
>
> Thank you in advance
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>

(I failed to send my original reply to the list)

Notice the Usage message when you run the example:

 $ python parser.py -q
 Usage: parser.py [options] arg

 parser.py: error: incorrect number of arguments

"-q" is an option, not an argument. If you look at the example, you add options:

 parser.add_option("-q", ...

The arguments are everything left over. In this case, they are not
used, but they are required. The following runs without issue:

 $ python parser.py junk
 $ python parser.py -v junk
 reading None...

The bottom line is the example is just an example, not something you
can use as is.

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


[Tutor] Need help in learning Python

2018-08-11 Thread Carlos Monge
 I bought two books to help me learn Python. "Python Crash Course" and
"Python for Informatics". I have done all of the basic lessons in "Python
Crash Course", but it has two additional sections to help instill what I
have learned To do those sections I need to install Pygame and make sure I
have 'pip' as well as Matplotlib. I have followed the directions in the
book but can't get anything to download so I can use it.
 For the "Python for Informatics" book I need to have files from the
internet load where I have Python so I can manipulate them, but I can't
seem to get that to work.

 Also, I would like to install Ubuntu on a second drive with Python,
Idle, C language and its compiler so I can also learn Linux. On the Linux
drive, I need to install Kali Linux for a class on Cyber Security.
 I know this is a lot to ask, but I don't need it all at once. I would
appreciate help from someone with experience in downloading all of these
things onto a windows computer with a second drive for Ubuntu and all of
the other software.
 Any help is appreciated, and if I find someone with the needed
expertise, I will happily subscribe on the Python-Tutor Info Page/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help in learning Python

2018-08-12 Thread Carlos Monge
Thank you all. I will start in small steps. First Pygame and Ubuntu. I will
add any errors I get.

On Sun, Aug 12, 2018 at 11:51 AM, Mats Wichmann  wrote:

>
> > Start with checking that pip is there (or installing it if not)
> > Then do PyGae
> > Then do Matplotlib
>
> For this, please note that the pip "command" is not in the same
> directory on Windows as the python it is associated with.  If you went
> through the steps to have Python in your PATH, and that works, then add
> another entry that is just the same but appends the \Scripts comoponent;
> OR where your instructions tell you to "pip install foo" at a command
> prompt do instead "python -m pip install foo"  I believe the latter is
> now the recommended way anyway, because it ensures the pip matches the
> python in case you have more than one copy installed on your system.
>
>
> For your other questions, you could instead of making  dual-boot setup,
> do some initial experiments with running a Linux virtual environment.
>
> Here's one possibility which will give you a ton of Python stuff already
> set up:
>
> https://labs.fedoraproject.org/python-classroom/download/index.html
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [OT] Re: Need help in learning Python

2018-08-13 Thread Carlos Monge
Ok, this may have been a fatal error on my part but I decided to start
fresh and uninstalled my old version of Python. Now when I try to reinstall
I get these error messages..


Setup failed

one or more issues caused the setup to fail. Please fix the issues and then
retry setup. For more information see the log file.

0x80070643- Fatal error during installation.


I don't understand what the problem is because it is supposedly installing
to=
C:\Users\cmongeoroplate09\AppData\Local\Programs\Python\Python37-32



I also get another error message that says:

The TARGETDIR Variable must be provided when invoking the installer


I don't know what's happening.

On Mon, Aug 13, 2018 at 3:17 AM, Wallis Short 
wrote:

> Hi Alan
>
> Have a look here - I could write it but why invent the wheel :)
>
> https://www.howtogeek.com/249966/how-to-install-and-use-
> the-linux-bash-shell-on-windows-10/
>
> A quick "How To" to remote ssh into the WSL once installed
> sudo apt-get install openssh-server
>
> sudo vi /etc/ssh/sshd_config
> PermitRootLogin no
>
> PermitRootLogin - we need to change this to no
> PasswordAuthentication - We need to change this to yes
> UsePriviledgeSeperation - We need to change this to no
>
> Go to end of file (Shift G)
> insert
>
> AllowUsers ubuntu  (or whatever name you chose when you installed WSL)
>
> bounce the SSH service.
>
> sudo service ssh --full-restart
>
>
> *Wallis Short*   Senior Network Engineer
>
> 
>
> Metro Fibre Networx (Pty) Ltd
> www.metrofibre.co.za
>
> 298 Witch-Hazel Ave, Highveld, Centurion, Gauteng, 0157 South Africa
>  +Centurion,+Gauteng,+0157+South+Africa&entry=gmail&source=g>
>
>
> On 13 August 2018 at 10:02, Alan Gauld via Tutor  wrote:
>
> > This thread is getting seriously off topic, but I'm
> > interested so I'm letting it run... :-)
> >
> > On 13/08/18 07:46, Wallis Short wrote:
> > > To learn Ubuntu, I would recommend installing Windows Subsystem for
> Linux
> > > onto your existing Windows 10 setup  and then get the Ubuntu (or SUSE
> and
> > > Debian) from the Microsoft store and install. It does have a few
> > > limitations (especially on the GUI) but again which proper Linux
> Sysadmin
> > > uses the GUI :)
> >
> > This is news to me. Can you elaborate a little on what
> > exactly this Linux Subsystem for Windows does? Does it
> > let me run Linux binaries under Windows? And if so how
> > do they show up on screen?
> >
> > This could potentially be very useful for something
> > I'm currently working on...
> >
> > PS. I probably should just google it, but since
> > you appear to have hands on experience...
> >
> > --
> > Alan G
> > Author of the Learn to Program web site
> > http://www.alan-g.me.uk/
> > http://www.amazon.com/author/alan_gauld
> > Follow my photo-blog on Flickr at:
> > http://www.flickr.com/photos/alangauldphotos
> >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
> >
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Reading Excel Files

2010-06-22 Thread Carlos Daniel Ruvalcaba Valenzuela
Hello list,

I was wondering if anyone has worked with excel 2007 files (importing
data from), I have done so for old format (xls) via a number of
modules like xlrd and the old pyexcelerator, however none of those
packages currently support new 2007 format, although xlrd may have
support for it later.

Has anyone had to deal with something like this recently?, I'm
thinking as last resort just work with the underlying XML files of the
format, but it would be nice to have an already working module.

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


Re: [Tutor] Reading Excel Files

2010-06-22 Thread Carlos Daniel Ruvalcaba Valenzuela
That is what I'm currently doing (telling users to convert), however
users tend to forget to save the file in old format or find it too
much a hassle to do the extra step, in which case I would like to be
able to read the new format, although I may just trow and error and
recommend the user to convert the format, lets see how they take that.

Regards,
Carlos Ruvalcaba

On Tue, Jun 22, 2010 at 10:44 PM, Lang Hurst  wrote:
> Carlos Daniel Ruvalcaba Valenzuela wrote:
>>
>> Hello list,
>>
>> I was wondering if anyone has worked with excel 2007 files (importing
>> data from), I have done so for old format (xls) via a number of
>> modules like xlrd and the old pyexcelerator, however none of those
>> packages currently support new 2007 format, although xlrd may have
>> support for it later.
>>
>>
>
> Couldn't you just save it in the older format?
>
>> Has anyone had to deal with something like this recently?, I'm
>> thinking as last resort just work with the underlying XML files of the
>> format, but it would be nice to have an already working module.
>>
>>
>
> The files I work with are pretty basic, so I just export them as cvs and
> work from there.  Probably not what you want.
>
>> Regards,
>> Carlos Ruvalcaba
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>>
>
>
> --
> There are no stupid questions, just stupid people.
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reading the CDROM in Linux

2010-11-05 Thread Carlos Daniel Ruvalcaba Valenzuela
This is more of a Linux question, but here is some advice:

All files under /dev are more or less raw representations of the
devices, meaning that /dev/cdrom or /dev/sr0 files represent the CDROM
devices, however this is for raw access to the device data, now really
for normal use, the sistem may "mount" this device in another place
(like inside the /media directory), so that a directory will represent
the contents (filesystem) of the device, which is what you may want to
use.

In the example that you are using, you may call 'df' from python and
parse the data, which more or less is presented in the following
format: device, space, used space, mounted directory. What you need
the the directory where the device is mounted (the last data), and
then you may use walk on that, taking care that the directory is under
your media directory so that you won't walk the root directory
entirely (your hard disk).

You may want to use os.popen or one of the many process modules to
call 'df', then parse each line by spliting the spaces or tabs, then
the rest is more or less what you are doing right now.

Regards,
Carlos Ruvalcaba

On Fri, Nov 5, 2010 at 5:59 PM, Terry Carroll  wrote:
> Alan Gauld wrote:
>
>> I don't use Ubuntu so don;t know the standard anmswer
>> there but it will depend on where the CD is mounterd.
>>
>> I usually mount cdroms on /dev/cdrom
>
> That's what I figured; I now realize I didn't say so in my email, but it's
> mounted at /dev/sr0, which is where I came up with that mount point.
>
>
>  t...@vraspberry:~$ df
>  . . .
>
>  /dev/sr0               614350    614350         0 100% /media/MP_04_074
>
>
> MP_04_074 is the volume name.
>
> But in python:
>
>>>> import os
>>>> for (r, d, f) in os.walk("/dev/sr0"): print r, d, f
>
> ...
>>>>
>>>> for (r, d, f) in os.walk("/dev/sr0/"): print r, d, f
>
> ...
>>>>
>>>> for (r, d, f) in os.walk("/dev/cdrom/"): print r, d, f
>
> ...
>>>>
>>>> for (r, d, f) in os.walk("/dev/cdrom"): print r, d, f
>
> ...
>>>>
>>>> for (r, d, f) in os.walk("/dev/cdrom0"): print r, d, f
>
> ...
>>>>
>>>> for (r, d, f) in os.walk("/dev/cdrom0/"): print r, d, f
>
> ...
>
>
> None of those work; but:
>
>
>>>> for (r, d, f) in os.walk("/media/MP_04_074"): print r, d, f
>
> ...
> /media/MP_04_074 ['directory1'] []
> (etc.)
>
>
> What I can't figure out is how to do this if my program does not know the
> volume name.  I won't know the colume name in advance, and in fact, I'll be
> processing one CDROM, replacing it and processing another, etc.
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Code documentation

2009-03-03 Thread Carlos Daniel Ruvalcaba Valenzuela
Hello list,

I have been coding in python a short while and I have been wondering
which approach should I take on documentation (API docs) for a python
library I have been working on, there is currently code docstrings,
docstrings with some markup (epydoc, etc), or external programs such
as Sphinx (reStructuredText markup).

In your experience which way is the best or what
advantages/disadvantages do you see (experienced) with each approach
that you are familiar.

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


Re: [Tutor] wxPython GUI builders?

2007-06-13 Thread Carlos Daniel Ruvalcaba Valenzuela
wxGlade is a good GUI builder, very much like Glade, however it may o
may not integrate with your coding style but you should definitively
give it a try.

PythonCard is a nice concept I personally do something similar but
with XML, parse and build the GUI from it, then tweak the layout
manually, with PythonCard this is easier to do since it has a resource
editor.

Personally I would like an IDE + wxPython GUI editor integrated, that
would help a lot, I'm starting to work on that myself.

Good luck!

On 6/13/07, Alan Gauld <[EMAIL PROTECTED]> wrote:
> What's available and in what state of readiness?
>
> I tried Boa Constructor but after half a dozen code tweaks
> I was still running into compatibility errors with the latest
> wxPython and gave up.
>
> I know that Glade is out there, but what state is it in?
> And PythonCard offers another approach but I haven't
> looked at it for about 3 years.
>
> Are there any others? And which ones do people
> actually use? Commercial or Freeware.
>
> Alan G.
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running another program from Python

2007-07-20 Thread Carlos Daniel Ruvalcaba Valenzuela
There is also os.system which should work in a similar way as Matlab
system. You pass a string with the command and arguments. The downside
of system is that it opens an entire shell and environment for the
program being run, you only have the return value from the
application.

Other options can be popen if you want to feed to process with some
information or get some information from it (if everything is done
through standard input and output), but in your case you are better of
with exec or system.

Exec functions will replace your current process with the application
you want to run, this may not be what you want.

Spawn will create a subprocess, you can wait for it to finish or let
it run free knowing its process id to check it latter, it is roughly
similar to fork.

Good luck!
Regards,
Carlos Daniel Ruvalcaba

On 7/20/07, Chris Smith <[EMAIL PROTECTED]> wrote:
> Howdy,
>
> I am working on some research. I'm trying to optimize the performance of
> an antenna. For the simulation of the antenna it would be easiest to use
> an antenna software package that I have in my lab. I know that Matlab
> can call the antenna software through a command called system. Matlab
> also uses system to pass a VB script file to the antenna software that
> tells the software what to do. However, I don't have access to Matlab in
> my lab.
>
> I use Python for a lot of program prototyping, and was looking through a
> Python reference book to see if there was something in there I could
> use. I ran across two functions that I thought might work. They are in
> the os module and are the different exec functions and also the spawnv
> function.
>
> The python program would run something like this:
> 1) optimization program comes up with initial variables to try
> 2) a VB script is generated
> 3) antenna program called and given the VB script
> 4) antenna program evaluates the antenna
> 5) results are sent back to optimization program
> 6) optimization program evaluates results and generates new variables
> 7) process from 2 on is repeated
>
> Would either of these two functions be what I need?
>
> Thanks for your help.
>
> Chris S.
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] gotoxy

2007-08-01 Thread Carlos Daniel Ruvalcaba Valenzuela
You should have a look at the curses module, basically gotoxy is a
borland think, in linux and other unix systems there is the curses
library for working with text screens.

Module documentation:
http://docs.python.org/lib/module-curses.html

Some tutorials:
http://www.amk.ca/python/howto/curses/
http://www.ibm.com/developerworks/linux/library/l-python6.html

Checkout window objects, there is functions for all that you want to
do (move cursor, print, read, etc).

Good Luck!
Carlos Ruvalcaba Valenzuela

On 8/1/07, Robert William Hanks <[EMAIL PROTECTED]> wrote:
>
>  hi folks, is there in python a gotoxy like in pascal so i can print stuff
> in other parts of the screen?
>  what about some thing like it for the gui in windows?
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Plz help me from this

2007-09-04 Thread Carlos Daniel Ruvalcaba Valenzuela
Yes is very possible to do this with python.

Checkout the os.system and os.popen functions to run external commands
(chmod, chown).

Reading the list of users and groups should be easy, just open the
file and read line by line and parse, you can do it as simple as
splitting the line on colon character (:) and parsing the resulting
list.

It seems you will also need some form of UI, simple print and
raw_input may do the trick.

On 9/4/07, chinni <[EMAIL PROTECTED]> wrote:
> Hi All,
>
>
> I Want to write a python script to change the permissions(chmod) and
> owner(chown) and group(chgrp) of a file on unix,
> script as to read from the /etc/passwd for displaying available users on the
> machine and from /etc/groups it as to display the available groups and user
> has to give the mode and owner name and group name from the list.
>
> Can i implement this in python or in shell scripting
> Can any one please suggest me from doing this...:)
>
> --
> Best Regards,
> M.Srikanth Kumar,
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] performance

2007-09-16 Thread Carlos Daniel Ruvalcaba Valenzuela
Don't worry too much for the accessors, I'm pretty sure it won't
degrade your performance in a noticeable way, you objects will only
grow a tiny bit by adding a function to the class, all objects share
the same in memory code and each one has it's own data, the function
for the object is just a reference for the class function, not the
memory of the function itself (I think, it would be a waste of memory
otherwise).

However take it with a grain of salt, do your own benchmarks, you
could do a simple measure with time.time() function, or use one of the
several profiling modules for python (profile, hotshot, etc).

Forwarded to Tutor list, I forgot it sorry!

Regards,
Carlos Daniel Ruvalcaba Valenzuela

On 9/16/07, Jeff Peery <[EMAIL PROTECTED]> wrote:
> Hello,
> I've got a quick question regarding performance of lists. I am taking
> measurements and building up a list of objects for each measurement. the
> class I created for the objects has attributes of time, numerical value,
> person's name who collected the sample etc. I also have functions within my
> class (I think they are properly named 'accessors'?) that get a piece of
> data within the object, for example 'self.GetSampleTime()'. I'm wondering
> what happens to my performance as I add more accesors to my class. How are
> the accesors managed? will each object in my list of objects contain the
> data for each accesor or do all the objects look to the sample module for
> the accesor? will my list of objects become huge and slow as I add more
> accessors? thanks.
>
> Jeff
>
>  
> Don't let your dream ride pass you by. Make it a reality with Yahoo! Autos.
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2005-09-14 Thread Carlos Eduardo Sotelo Pinto
Hi List.
All of you are right. It is similar to java, vb, but how it work?

Well, python script generates a compiled bytecode the first time that 
yuou run the main script in a machinne, and the interpreter execute this 
byte code.

It could be slower than a compiled language, because use an interpreter 
to run, but it is faster than a interepreted language, because the 
interpreted language ot generated a byt code, this one reads the secripts.

About operating system, it coulbe posible, but not at all. First to run 
an operative systems you need a low level language, like assembler, it 
could began the os, but the kernel could be in python.
just a c library or gcc and python interpreter. if you use assembler to 
run with c, u can use python for your python os


Alan G wrote:
>>I am new to Python, about 1 day. And I downloaded from
>>python.org Pythong2.4, it has the command line and
>>junk. But what actuall program compiles the source of
>>python into a program? 
> 
> 
> When you run a python script python compiles the source 
> internally before executing it. If your program imports 
> modules, the imported code gets converted into compiled 
> code and you will see it in the form of .pyc files.
> 
> Python works in a similar fashion to VB and Java in that 
> it executes compiled byte code, not native machine code.
> The Python program has the same function as both the 
> Java compiler and JVM interpreter.
> 
> If you use Jython instead of Python you will find a separate 
> python compiler that produces true Java code that then 
> can be run under any JVM.
> 
> If you want to produce standalone windows executables 
> there are several tools available, the simplest and 
> most widely used being py2exe. This is not part of the 
> standard distribution however. Basically what all these 
> tools do is wrap the Python program and all of the 
> modules you use into one single executable file - so 
> its quite big and if you distribute several programs 
> you duplicate python with each one!! In this case 
> distributing the python scripts with a one-off version
> of Python is a better option.
> 
> The included distutils package can simplify that process.
> 
> 
>>And also, is Python capable of writing an OS?
> 
> 
> Not really since python requires the python program to 
> be present in some form and it itself needs an underlying 
> OS. You could write an OS simulation as a learning 
> excercise but it would need a minimal OS underlying it.
> Python is a high level programming language aimed at 
> developing applications with the minimum effort. If you 
> really need to twiddle the bits n' bytes you are better 
> off with C or assembler, just be prepared to write a 
> lot of code...
> 
> HTH,
> 
> Alan G
> Author of the Learn to Program web tutor
> http://www.freenetpages.co.uk/hp/alan.gauld
> _______
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
Atentamente:

**  ,= ,-_-. =.
|Carlos E. Sotelo Pinto(KrLoS)   | ((_/)o o(\_))
|GNU/Linux User Registered # 379182  |  `-'(. .)`-'
|Tildes omitidas voluntariamente |  \_/
**
Bitacora de Vuelo <http://csotelop.blogsome.com/>
Sociedad Peruana de Computacion <http://www.spc.org.pe/>
Grupo de Usuarios GNU/Linux Arequipa <http://www.aqpglug.org.pe/>
Grupo de Usuarios Debian Arequipa <http://www.debianarequipa.org>
Grupo de Usuarios Debian Peru <http://www.debianperu.org/>

La actitud del hacker:
Los hackers resuelven problemas y construyen cosas, y creen en la 
libertad y la ayuda voluntaria mutua. Para ser aceptado como hacker, 
deberás comportarte como si tuvieras esta actitud en tu interior. Y para 
comportarte como si tuvieras esta actitud, deberás creerte de verdad 
dicha actitud.





__ 
Renovamos el Correo Yahoo! 
Nuevos servicios, más seguridad 
http://correo.yahoo.es
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Spanish Tutorials

2006-05-13 Thread Carlos Daniel Ruvalcaba Valenzuela
Hello!

At my university we are creating a Wiki with information about the
careers and articles, one of the most important section is the Systems
Engineering, which sports a Python section :)

Spanish Python Tutorials at:

http://wikitec.itnogales.edu.mx/index.php/Python

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


Re: [Tutor] python simulations - saving state

2006-05-16 Thread Carlos Daniel Ruvalcaba Valenzuela
Depends, you can pickle the list, but all objects need to be
pickleable, maybe you can put up with this requeriment by changing
your events to be pickleable?, but i don't know what data you store in
a event or what kind of data is it.

Regards

On 5/16/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am fairly new to programming in python, but for work I am running a 
> simulation
> of a distribution center.  What I am trying to do now is to save the state of
> the simulation (i.e. the event list and any other necessary variables) so that
> it can be "restored" later.  I eventually want to be able to save the state of
> the simulation and restart it as well as being able to save periodically and
> change the event list for changes in the simulation (i.e. for a distribution
> center if a truck is running late and will not be arriving on time I would 
> need
> to modify it's arrive time and see how that would change the execution of the
> rest of the simulation).
>
> I have found I can't pickle _e (the event list) and I was wondering what
> suggestions you could give or where I could go to get more help on this topic.
>
> Thanks,
> Sarah Moody
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] implementing config files

2006-06-01 Thread Carlos Daniel Ruvalcaba Valenzuela

Your could try to use XML files to store configuration files, I
already coded something like that, using expat parser and loading the
XML contents to objects and attributes, this is a sample code of how
works my module:

Lets supouse we have this file config.xml with the following contents:


   
   MySQL
   localhost
   21
   username
   
   


and in our code:

from objxml import *

fd = file('config.xml', 'r')
p = XMLParser(fd)

root = p.Root
port = str(root.connection.port)
user = str(root.connection.username)

All nodes are objects, converting them to strings gets you the
content, you can also access the atributes as normal object
attributes.

This code can be useful for what you want, take a look.

Regards
Carlos Daniel Ruvalcaba Valenzuela


On 6/1/06, Tracy R Reed <[EMAIL PROTECTED]> wrote:

Hello all!

I am writing some code to implement a bunch of passive checks for the
nagios network monitoring system. It runs some checks on the local
machine and reports the results back to the nagios server using rpc
calls via Perspective Broker from the Twisted module. This code and
associated config file is distributed to all of the machines in my
infrastructure by cfengine. This part all works quite well. Now I need
to refactor my code into a more general and flexible infrastructure and
provide a way to configure the services being checked instead of hard
coding them (as they currently are).

I need to implement a config file which will provide hostnames, the
names of checks to run on those hosts, and the options to those checks.
These things are sets which are nested inside each other which we can
think of like nested objects. I could make a dictionary containing the
host names each of which is a dictionary containing the services to be
checked etc.

But rather than just make dictionaries of dictionaries (which could get
confusing) I was wondering if I could make it more robust by somehow
defining objects nested inside of other objects in the config file with
certain attributes. For example I would like to be able to have a
check_tcp object which would have two attributes: hostname and port. If
you try to assign it anything else you get an error. If port isn't a
number between 0 and 2^16 you get an error. Etc. Basically I don't want
errors in the config file to propagate all the way to the client machine
on which the code is going to be executed and have wrong arguments
passed to the program which we os.popen() and read the results from.

Anyone have suggestions on how to proceed? I'm sure the problem of
parsing config files into useful objects must be a solved one...

I will eventually be posting a link to my code for others to use and
critique. It has been a neat project so far.

--
Tracy R Reed  http://ultraviolet.org
A: Because we read from top to bottom, left to right
Q: Why should I start my reply below the quoted text

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

import xml.parsers.expat

class ObjXML:
	Attribs = {}
	Children = {}
	Data = None
	Parent = None
	Name = ""
	
	def __init__(self, parent, name, attrs = {}):
		self.Attribs = attrs
		self.Parent = parent
		self.Name = name
		
		if type(parent) != type(None):
			parent.Append(self)
	
	def Append(self, obj):
		self.Children[obj.Name] = obj
		
	def FileXML(self, fd):
		fd.write("<" + self.Name)
		
		for a in self.Attribs:
			fd.write(" " + self.Name + """="""" + self.Attribs[a] + """" """)
		
		fd.write(">")
		
		#We cannot have nodes with data and children at the same time
		if len(self.Children) > 0:
			for c in self.Children:
self.Children[c].FileXML(fd)
		else:
			fd.write(self.Data)
			
		fd.write("")
	
	def __str__(self):
		if type(self.Data) == type(None):
			return ""
		return self.Data.encode('ascii')
		
	def __repr__(self):
		if type(self.Data) == type(None):
			return ""
		return self.Data

	def SetAttrib(self, name, value):
		self.Attribs[name] = value
			
	def __getattr__(self, name):
		if (self.Children.has_key(name)):
			return self.Children[name]
		
		if (self.Attribs.has_key(name)):
			return self.Attribs[name]
			
		#self.__dict__[name]
		
		

class XMLParser:
	Root = None
	
	def start_element(self, name, attrs):
		if type(self.Root) == type(None):
			self.Root = ObjXML(None, name, attrs)
		else:
			c = ObjXML(self.Root, name, attrs)
			self.Root.Append(c)
			self.Root = c
		
	def end_element(self, name):
		if type(self.Root.Parent) != type(None):
			self.Root = self.Root.Parent
		
	def char_data(self, data):
		if str(data)[0] != "\n":
			self.Root.Data = str(data)
	
	def __init__(self, fd):
		p = xml.parsers.expat.ParserCreate()
		
		p.Start

Re: [Tutor] Trouble with os.path.isfile

2006-06-02 Thread Carlos Daniel Ruvalcaba Valenzuela
From: Carlos Daniel Ruvalcaba Valenzuela <[EMAIL PROTECTED]>
Date: Jun 2, 2006 11:10 PM
Subject: Re: [Tutor] Trouble with os.path.isfile
To: "Carroll, Barry" <[EMAIL PROTECTED]>


Here is the problem IMO:

I did some modifications to your code (very minimal on ifs) and it worked:

import os

def lstdirsnfiles(tdir):
flst = os.listdir(tdir)
flst.sort()

fnames = []
dnames = ['.', '..']

for name in flst:
absfn = os.path.join(tdir, name)

if os.path.isdir(absfn):
dnames.append(name)

if os.path.isfile(absfn):
 fnames.append(name)
return (dnames, fnames)

(dirs, files) = lstdirsnfiles('/home/clsdaniel')

It returns correctly all directories and files.

Regards
Carlos Daniel Ruvalcaba Valenzuela
On 6/2/06, Carroll, Barry <[EMAIL PROTECTED]> wrote:
>
>
>
>
> Greetings:
>
>
>
> One of the functions of my test system web server program is to allow the
> user to view the contents of the image file directories and select files to
> load onto the hardware.  Obviously, a central part of this function is to
> identify and display the names of directories and files in a specified
> directory.  I haven't been able to find any canned code or cookbook entries
> that do this, so I'm making one from scratch.  Here is the helper function
> that gets and returns the  directory and file names:
>
>
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>
>
> def lstdirsnfiles(tdir):
>
> flst = os.listdir(tdir)
>
> flst.sort()
>
> fnames = []
>
> dnames = ['.', '..']
>
> for name in flst:
>
> absfn = os.path.join(tdir, name)
>
> if os.path.isdir(absfn):
>
> dnames.append(name)
>
> elif os.path.isfile(absfn):
>
>  fnames.append(name)
>
> return dnames, fnames
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>
>
>
>
> The root of the image file directory tree is "/home/iip/images".  When
> lstdirsnfiles is run with tdir set appropriately,  the lists returned
> contain no additional information: dnames = ['.', '..'] and fnames = [].  I
> added some tracing statements to see what was happening inside the
> function:
>
>
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>
>
> def lstdirsnfiles(tdir):
>
> global DEBUG, dbgfname
>
> DEBUG = True
>
>
>
> flst = os.listdir(tdir)
>
> flst.sort()
>
> fnames = []
>
> dnames = ['.', '..']
>
>
>
> if DEBUG:
>
> dbgf = open(dbgfname,mode="a")
>
> dbgf.write("\n"+str (time.localtime())+"\n")
>
> dbgf.write("Entering lstdirsnfiles\n")
>
> dbgf.write("The directory = %s\n" % tdir)
>
> dbgf.write("The file list = %s\n" % flst)
>
>
>
> for name in flst:
>
> absfn = os.path.join(tdir, name)
>
>
>
> if DEBUG:
>
> dbgf.write("File path = %s, isfile = %s\n" %
>
>(absfn, os.path.isfile(absfn)))
>
>
>
> if os.path.isdir(absfn):
>
> dnames.append(name)
>
> elif os.path.isfile(absfn):
>
>  fnames.append(name)
>
>
>
> if DEBUG:
>
> dbgf.write("dnames = %s\n" % dnames)
>
> dbgf.write("fnames = %s\n" % fnames)
>
> dbgf.close()
>
> DEBUG = False
>
>
>
> return dnames, fnames
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>
>
>
>
> The log vile received the following:
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>
>
> (2006, 6, 2, 15, 23, 4, 4, 153, 1)
>
> Entering lstdirsnfiles
>
> The directory = /home/iip/images
>
> The file list = ['test1.bmp', 'test2.bmp', 'test3.bmp', 'test4.bmp',
> 'test5.bmp', 'test6.bmp']
>
> File path = /home/iip/images/test1.bmp, isfile = False
>
> File path = /home/iip/images/test2.bmp, isfile = False
>
> File path = /home/iip/images/test3.bmp, isfile = False
>
> File path = /home/iip/images/test4.bmp, isfile = False
>
> File path = /home/iip/images/test5.bmp, isfile = False
>
&

Re: [Tutor] PyGTK on cygwin

2006-06-08 Thread Carlos Daniel Ruvalcaba Valenzuela
There is a PyGTK package for win32, don't know if it uses cygwin or
mingw but works pretty well on windows, it only needs the gtk runtime.

http://www.pcpm.ucl.ac.be/~gustin/win32_ports/

Altough I might been misunderstanding your question ;)

On 6/8/06, Christopher Spears <[EMAIL PROTECTED]> wrote:
> Does PyGTK work well on cygwin?
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what does the warning indicate?

2006-06-22 Thread Carlos Daniel Ruvalcaba Valenzuela
Most probably you are using Python on Windows, on Unix-like system
there is a "home" for each user where the user files reside, normally
HOME on windows must point to something like c:\Documents and
Settings\Username, are you using Python on Windows 98?

Otherwise it may be a problem with the enviroment variable (Home),
pointing to drive H (H:), while it dosen't exist in your system.

Anyways, that's my 2 cents :)


On 6/22/06, devayani barve <[EMAIL PROTECTED]> wrote:
>
> Hi!!
> I'm new to python and just trying to play around,
> when I run my program in the interactive shell before executing the program
> it shows the following warning :
>
>  Warning: HOME environment variable points to
>  H:
>  but the path does not exist.
>  RESTART
> 
> >>>
>
> or sometimes it just gets stuck.
> What does this mean?
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what does the warning indicate?

2006-06-23 Thread Carlos Daniel Ruvalcaba Valenzuela
By the way, when do you get this warning? while starting the python
interpreter (python.exe)?, it's IDLE which gives you that warning? or
could it be some code? if it is code then send it to the list, i'm
sure will be able to help you more that way :)

Regards,
Carlos Daniel Ruvalcaba
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] File compression

2006-06-27 Thread Carlos Daniel Ruvalcaba Valenzuela
I think this is something that can be easily madded with some shell
scripting, i suppose you are using Linux or a Unix derivate.

In this case tar + bzip2 is your friend, altough for the volume of
files i sugest looking at something like rsync or unison and coupling
it with cron for automating the online backup.

Otherwise i suggest looking at glob module for listing directories and
files and the bz2 module, there is also ziplib module, check the docs:

http://docs.python.org/lib/someos.html

As for ftp, there is ftplib:

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


Good luck, regards
Carlos Daniel Ruvalcaba

On 6/27/06, Magnus Wirström <[EMAIL PROTECTED]> wrote:
> Hi Everyone
>
> I'm starting to python and i need to write a program that are able to
> compress a high amount of files and directories into a single file that
> is later going to be transfered  with ftp to a  backup storage server.
> The data is a quite big amount (over 1.5 gb in 4 files and 1300
> directories) so i would like to have high compression like RAR or bz2.
> What way is the best to approach this? I have looked a bit on zlib but i
> didn't find a good example that uses it to compress files and
> directories in one file from python. or perhaps it's simpler to execute
> a external program, doing the work. I would prefer to use python as much
> as i can without external apps.
>
> Does anyone have a idea how this can be made with python.
>
> Thanks
> Magnus Wirström
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Two Newbile Questions: porting drawmap.c, & Python as a lifetime language

2006-07-04 Thread Carlos Daniel Ruvalcaba Valenzuela
Really depends on what you do, if you program for a living most
probably you'll use whatever your employer tells you to use, if you
work by yourself you can choose, personally i like python because of
the enormous amount of modules available to do all sort of stuff, from
GUI programing, to unittest, database, compression, graphics (OpenGL),
etc.

I like it because is crossplatform, it may not be fast but most
modules are written in C already and are fast.

I like the ability to use py2exe and generate a windows executable in
a folder with ALL that i need to deploy on windows, i just copy the
folder and i'm done.

The Python comunity is very nice too, this is a big plus if you are
learning a new languaje, the tutor list is always very helpful and
active.

You can always make use of your C skills even on Python, by writting
modules to extend python functionability or to speed it up.

Good Luck!

Regards
Carlos Daniel Ruvalcaba Valenzuela

On 7/4/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > 2. Seeing Python hailed as a good language for learning programming,
> > how do you
> > rate it as a lifetime language? (I can imagine that many people have
> > settled into one language for doing the remainder of their life's work. 
> > If
> > I am pressed, I will choose Perl at this point.)
> Python is great as a general-purpose programming language and it is my
> language of choice today. But I'll be pretty surprised if it keeps the
> spot on the top of the heap for the rest of my working life...
>
> Kent
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] GUI with Designer

2006-11-03 Thread Carlos Daniel Ruvalcaba Valenzuela
wxPython is good for cross-platform stuff and has a few gui designers
(Boa Constructor and others comes to mind), I don't know much about
PyQT state in this, but PyGtk + Glade (Gui Designer) is a very good
combo.

Is about choise, I suggest you to do some simple tests with everything
until you find something to be confortable with.

* PyGtk + Glade
* Boa Contructor
* SPE + wxPython

On 11/3/06, Todd Dahl <[EMAIL PROTECTED]> wrote:
> I am wanting to get into some GUI coding with Python and have heard about
> PyQT and wxPython. Now I am definately not looking for some type of holy war
> but can anyone give me a good reason to pick one over the other.
>
> Also I would like to have a designer with it or a seperate designer that
> could be used with either. I plan on coding in Windows XP.
>
> Thanks,
>
> -Todd
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Game server login encryption

2006-12-24 Thread Carlos Daniel Ruvalcaba Valenzuela
You can use SSL encripted connections, for logon and all session if
you like, socket module has SSL support too:

http://docs.python.org/lib/module-socket.html
http://docs.python.org/lib/ssl-objects.html
http://docs.python.org/lib/socket-example.html  (check last example)

As for hashes, password hashing with md5, most sites or systems
authenticates against the hash, never use the clear password, a hash
is better and can be faster.

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

Regards,
Carlos Daniel Ruvalcaba Valenzuela

On 12/24/06, Adam Bark <[EMAIL PROTECTED]> wrote:
> I'm currently writing a networked game and I'm about to write a proper
> implementation of the logon server. I would prefer to have some sort of
> encryption but would like some opinions. The way I see it either I can take
> a hash of some data eg. username, password, port and ip and check the hash
> against one generated on the server. Alternatively I could use twisted conch
> tunneling through ssh. I anybody has any opinions on either of these ideas
> or anything else that might be useful, fire away.
> Cheers,
> Adam.
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Does Python have any callback function?

2007-01-28 Thread Carlos Daniel Ruvalcaba Valenzuela
That depends very much on how you are running both scripts in
parallel, if you are using Threads or process.

If using threads you can share a variable or object between the
scripts read it on A to check for updates and lock and update on B
(using semaphores for examples), there is an Event object on the
threading module but i have never used it.

If you are using process (via system call or something like that, not
threading) then you need an IPC mechanism, like sockets, signals or
RPC.

There is many ways to approach this problem really, these are just my
2 cents :-).

Good luck.

On 1/28/07, Wong Vincent <[EMAIL PROTECTED]> wrote:
> Dear tutor,
>My current application has 2 python scripts running in parallel, say
> script A and B.
> script A: GUI
> script B: data processing.
>
> A will invoke B to run. If I would like B to update processing status to
> A(so that user is able to see realtime status), how can I do it?
>
> Appreciate your guidance...
>
> Best regards
> Vincent
>
>  
> Don't be flakey. Get Yahoo! Mail for Mobile and
> always stay connected to friends.
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mod python

2008-04-22 Thread Carlos Daniel Ruvalcaba Valenzuela
Hello, I think this is a problem with mod_python and Apache
configuration, you should checkout mod_python configuration for
Apache+Windows.

Most likely your problem is the mod_python library file, use this
instead (more appropiate for windows):

"LoadModule python_module modules/mod_python.dll"

I suggest you to consult the Apache configuration documentation on Windows.

Regards,
Carlos

On Tue, Apr 22, 2008 at 4:18 PM, SwartMumba snake <[EMAIL PROTECTED]> wrote:
> Hello Python Mailing List
>
> I am trying to set up mod python 3.3.1. I have python 2.5.1, apache 2.2
> server, and my os is Vista. The problem is that after I install mod python,
> there is no mod_python.so in the apache modules directory. Thus the
> "LoadModule python_module modules/mod_python.so" call does not work.
>
> What should I do.
>
> Thanks.
>
>  
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it
> now.
> ___
>  Tutor maillist  -  Tutor@python.org
>  http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Application packaging

2011-09-05 Thread Carlos Daniel Ruvalcaba Valenzuela
Hello list,

Lately I have been working on a windows desktop application for a client,
using python and pyside, everything working fine, but I'm getting a bit
stuck when trying to distribute the application to the client.

Currently I'm using a combination of py2exe and clickonce, what are your
experiences on distributing this kind of applications on a windows
environment?

Personally I have tried py2exe, pyinstaller, cx_freeze, only py2exe got me a
working bundle but a ugly one full of unordered files, I wrapped all this on
a ClickOnce installer so the user just sees an icon in their desktop. The
problem with this approach is that it results in a huge bundle, updates are
a pain too. Any ideas or experience with this (not precisely this combo but
the packaging in general)?

Regards,
Carlos Ruvalcaba

PD: I'm looking for the actual state of things right now as I'm sure this
questing has been asked in the past.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What made Python differ from other Languages?

2012-02-20 Thread Carlos Daniel Ruvalcaba Valenzuela
Just to express my opinion on the matter which is cannot stress
enough, Python does not only come with the kitchen sink, it comes with
a very useful kitchen sink, most of the standard library modules are
very useful and not just random additions, I take for example a
comparision against C#, I had to process some XML files from email
attachments, you cannot do this in C# out of the box (there is no pop3
or imap library, only XML handling), in python there is buildin pop3
module and xml processing, thus the time I invest on looking for a C#
pop3 library (or creating my own) I already got it done with python
and core modules, plus there is a standard way of searching, getting
and installing modules which makes developing with python a bliss.

To sum up, python is also different because there is a large amount of
libraries and code to harness, making it easy to work with, fast to
develop and flexible enough to cover different application types.

Regards,
Carlos Daniel Ruvalcaba Valenzuela
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor