Re: [Tutor] Proper uses of classes

2013-04-05 Thread Mark Lawrence

On 04/04/2013 18:01, frank ernest wrote:

Sorry about the indentation guys my mail service atomatically removed it
when I pasted the text (I tried to fix it by hand but it was hard to
tell if I was sucessful.)
I  was tring to create a list object (self) and change it using the list
methods and some additional ones I will define in my class.
I wanted to create some varibles which I pass to most if not all of my
methods. Two of my variables are to be passed to the class apon creation
of the object and then they in turn are to be passed to all or most of
the methods I create (a, b in this case.) If I make a, b nonlocal I get
the message that they are already nonlocal.
I will need for debuging purposes to print my object in random places in
my class.
If I did this:


self.a = a


What would that create (I'm thinking local variable?)?


If the line is in a class method you'd create a (using Python speak) 
name 'a' for every instance of your class.




class alist():
def __init__(self, b, a):
self.mylist = list()
self.mylist.append(b)
self.a = a + b
def appendit(self):

#I need to get a in hear without passing

#it in; it must come from the init method.
self.mylist.append(self.a)

#(I hope I've updated the code well, I can't test it from this 
computer.)

PS: This is not the real code that I'm Emailing: I thought I'd be better off 
with some simpler code that produces the same errors.



As I see it all you gain from the appendit method is the ability to 
delay adding 'a' to mylist until you've done some other processing.  Is 
this what you're trying to achieve, if not can you give us more detail? 
 That way we can help you code up your requirements.


--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: [Tutor] Proper uses of classes

2013-04-05 Thread Dave Angel

On 04/04/2013 01:01 PM, frank ernest wrote:

Sorry about the indentation guys my mail service atomatically removed it when I 
pasted the text (I tried to fix it by hand but it was hard to tell if I was 
sucessful.)
I was tring to create a list object (self) and change it using the list methods 
and some additional ones I will define in my class.
I wanted to create some varibles which I pass to most if not all of my methods. 
Two of my variables are to be passed to the class apon creation of the object 
and then they in turn are to be passed to all or most of the methods I create 
(a, b in this case.) If I make a, b nonlocal I get the message that they are 
already nonlocal.
I will need for debuging purposes to print my object in random places in my 
class.
If I did this:

self.a = aWhat would that create (I'm thinking local variable?)?


No.  a is a local variable, since it was passed as an argument.  self.a 
is an attribute of the alist instance.


class alist(): def __init__(self, b, a): self.mylist = list() 
self.mylist.append(b) self.a = a + b def appendit(self): #I need to get a in 
hear without passing  #it in; it must come from the init method. 
self.mylist.append(self.a) #(I hope I've updated the code well, I can't test it 
from this computer.)PS: This is not the real code that I'm Emailing: I thought 
I'd be better off with some simpler code that produces the same errors.




Your mail service is just broken, at least for use here.  This is a text 
forum, and your mail has an empty text body.  So each of our mail 
readers has to try to reconstruct the text from html nonsense.  You can 
see the result above of what Thunderbird does.


The following is what I think you posted.

class alist():
   def __init__(self, b, a):
   self.mylist = list()
   self.mylist.append(b)
   self.a = a + b
   def appendit(self):

   #I need to get a in hear without passing

   #it in; it must come from the init method.
   self.mylist.append(self.a)

   #(I hope I've updated the code well, I can't test it from this 
computer.)


There are lots of terminology problems which will stop you from 
understanding what's going on.


"I wanted to create some varibles which I pass to most if not all of my 
methods"


"Variables" passed to methods are called arguments, or parameters, and 
that's NOT what you're trying to do.  You're trying to have the 
__init__() method "remember" those values.  When you write "self.a =" 
you are creating an "instance attribute" which is visible to all methods 
on that instance.  Other methods can access that instance attribute by 
referring to it as  self.a   Not by "global" not by "nonlocal".  Those 
are very different.  A local variable is also different, as is a class 
attribute.  You need to study up on each of these terms, and see what 
the differences are in terms of lifetime, visibility, duplication, etc. 
 More on that later.


Now, the appendit() method is nonsensical, but perhaps it was just a 
sample.  Each time it's called, it'll append the same value a to the list.


Perhaps you'd be more comfortable if you wrote a __str__() method.  That 
way, when you try to print an instance, it'll do what you say, rather 
than some default.  Typically, it should do something with each 
attribute that was initialized by __init__().  (untested)


def __str__(self):
res = "mylist attribute is" + str(self.mylist) + "\n"
res += "a is " + str(a) + "\n"
return res

Now you can exercise your class, and print out the results as often as 
you like:  (untested)


obj1 = alist(3, 47)   # creates an instance of alist
print(obj1)   # prints it
obj2 = alist(12, 9)   # creates a second instance of alist, with its own 
self.mylist and self.a,  different from those in obj1

print(obj2)

obj1.append()   #will take the particular list in obj1, and append the 
saved self.a value

print(obj1)

obj2.append()
obj2.append()
print(obj)


Now, a brief, informal summary of all the different kinds of 
"variables."  A global variable is defined at the outer scope of a 
module, and should mostly be constants, for sound engineering reasons. 
The global keyword, used only inside a function, declares that a 
particular variable that looks like it ought to be local, in fact is 
global.  The keyword applies only to that particular function.


A local variable is defined and used within a function (or method), and 
vanishes entirely when the function returns.  The formal parameters of 
the function are locals as well.


A class attribute belongs to the class, and there's only one of them, 
regardless of how many instances that class has.


An instance attribute exists separately in each instance of a class.  It 
should (my preference) be initialized in the __init__() method so that 
every instance has the same attributes, even if it's just

 self.att = None

A nonlocal variable is probably beyond what you need to know at the 
present, but it's one that's either glo

[Tutor] Socket Programming

2013-04-05 Thread Mousumi Basu
I want to perform bind function for  socket programming between two
computers of ip addresses- 172.18.2.11 and 172.18.2.95 using the following
command(on the computer having IP address 172.18.2.95):

s=socket.socket(socket.AF_INIT,socket.SCK_DGRM))
s.bind(('172.18.2.11',8032))

But error is occurring showing "bind not done"

The ping operation of command prompt is showing that the computers are
connected.

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


[Tutor] basic question

2013-04-05 Thread Najam Us Saqib
Hi,

My name is Najam, I am very new to Python Programming. Would you please help me 
with the following question?

The question/problem is,

Write a Car salesman program where the user enters the base price of a car. The 
program should add a bunch of extra fees such as tax, license, dealer prep, and 
destination charge.Make tax and license a percent of the base price. The other 
fees should be set values. Display the actual price of the car once all the 
extras are applied.

I am not sure whether I have entered the right code for "Make tax and license a 
percent of the base price." or not.

My program is;

price = float(raw_input("Enter the base price of the car $ "))

tax = float(raw_input("Enter the tax $ "))
licence = float(raw_input("Enter the licence fees $ "))
dealer_prep = float(raw_input("Enter the dealer prep fees $ "))
des_charge = float(raw_input("Enter the destination charge $ "))

percent = (tax * 0.01 + licence * 0.01) / price                                 
  # ?

print "\nA percent of the base price is: $ " , percent

total = price + tax + licence + dealer_prep + des_charge

print "\nThe actual price of the car is: $ " , total

raw_input("\nPress Enter key to Exit, thank you.")



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


Re: [Tutor] basic question

2013-04-05 Thread Dave Angel

On 04/05/2013 08:05 AM, Najam Us Saqib wrote:

Hi,

My name is Najam, I am very new to Python Programming.


Welcome.


 Would you please help me with the following question?

The question/problem is,

Write a Car salesman program where the user enters the base price of a car. The 
program should add a bunch of extra fees such as tax, license, dealer prep, and 
destination charge.Make tax and license a percent of the base price. The other 
fees should be set values. Display the actual price of the car once all the 
extras are applied.



Is this exactly the way the assignment reads, or did you paraphrase it?


I am not sure whether I have entered the right code for "Make tax and license a 
percent of the base price." or not.

My program is;

price = float(raw_input("Enter the base price of the car $ "))

tax = float(raw_input("Enter the tax $ "))
licence = float(raw_input("Enter the licence fees $ "))
dealer_prep = float(raw_input("Enter the dealer prep fees $ "))
des_charge = float(raw_input("Enter the destination charge $ "))

percent = (tax * 0.01 + licence * 0.01) / price 
  # ?

print "\nA percent of the base price is: $ " , percent

total = price + tax + licence + dealer_prep + des_charge

print "\nThe actual price of the car is: $ " , total

raw_input("\nPress Enter key to Exit, thank you.")




The way I expect the assignment was intended is that the user should 
enter (with raw_input) the tax and license as percentages, and you 
convert them to dollars, rather than the other way around.



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


Re: [Tutor] basic question

2013-04-05 Thread Woody 544
On 4/5/13, Woody 544  wrote:
> Dear Najam
>
> The tax and license amounts should not need to be entered, as I would
> think the only variable is the base price, with tax and license
> calculated as their rate times the base price. For example, if the
> sales tax rate for the area is 6% for example:
>
> tax = price * 0.06
>
> Since the other fees are fixed, there is no need for raw input from
> the user on those either and the rates can be hard coded in.  If the
> tax rate = 6% and the license rate = 1% then:
>
> total = price + (price*.06) + (price * .01) + dealer_prep + des_charge
>
> Thus the only input from the user would be to enter the base price.
> Of course, if the intent is for more than just one dealership with
> varied rates and fees, it may make sense for the other values to be
> entered by a user.
>
> MJ
>
> On 4/5/13, Najam Us Saqib  wrote:
>> Hi,
>>
>> My name is Najam, I am very new to Python Programming. Would you please
>> help
>> me with the following question?
>>
>> The question/problem is,
>>
>> Write a Car salesman program where the user enters the base price of a
>> car.
>> The program should add a bunch of extra fees such as tax, license, dealer
>> prep, and destination charge.Make tax and license a percent of the base
>> price. The other fees should be set values. Display the actual price of
>> the
>> car once all the extras are applied.
>>
>> I am not sure whether I have entered the right code for "Make tax and
>> license a percent of the base price." or not.
>>
>> My program is;
>>
>> price = float(raw_input("Enter the base price of the car $ "))
>>
>> tax = float(raw_input("Enter the tax $ "))
>> licence = float(raw_input("Enter the licence fees $ "))
>> dealer_prep = float(raw_input("Enter the dealer prep fees $ "))
>> des_charge = float(raw_input("Enter the destination charge $ "))
>>
>> percent = (tax * 0.01 + licence * 0.01) / price
>>   # ?
>>
>> print "\nA percent of the base price is: $ " , percent
>>
>> total = price + tax + licence + dealer_prep + des_charge
>>
>> print "\nThe actual price of the car is: $ " , total
>>
>> raw_input("\nPress Enter key to Exit, thank you.")
>>
>>
>>
>> Thank you.
>> Najam.
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Socket Programming

2013-04-05 Thread Steven D'Aprano

On 05/04/13 21:47, Mousumi Basu wrote:

I want to perform bind function for  socket programming between two
computers of ip addresses- 172.18.2.11 and 172.18.2.95 using the following
command(on the computer having IP address 172.18.2.95):

s=socket.socket(socket.AF_INIT,socket.SCK_DGRM))



I get THREE errors with that line:

* SyntaxError due to an extra closing parenthesis;

* after fixing that problem, I get an AttributeError:
  'module' object has no attribute 'AF_INIT'

* after guessing what you mean instead of AF_INIT, I get another AttributeError:
  'module' object has no attribute 'SCK_DGRM'


Could you show us the code you are actually using, and save us from having to 
guess?



s.bind(('172.18.2.11',8032))

But error is occurring showing "bind not done"


Please copy and paste the complete traceback, starting with the line:


Traceback (most recent call last)


and going all the way to the end of the error message.





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


Re: [Tutor] Socket Programming

2013-04-05 Thread Chris Fuller

Have you checked out the socket HOWTO?
http://docs.python.org/2/howto/sockets.html

Cheers

On Friday, April 05, 2013, Mousumi Basu wrote:
> I want to perform bind function for  socket programming between two
> computers of ip addresses- 172.18.2.11 and 172.18.2.95 using the following
> command(on the computer having IP address 172.18.2.95):
> 
> s=socket.socket(socket.AF_INIT,socket.SCK_DGRM))
> s.bind(('172.18.2.11',8032))
> 
> But error is occurring showing "bind not done"
> 
> The ping operation of command prompt is showing that the computers are
> connected.
> 
> Please help me.

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


Re: [Tutor] TypeError: can't multiply sequence by non-int of type 'float'

2013-04-05 Thread Sayan Chatterjee
Thanks all...I realized my mistake!!...:)


On 4 April 2013 20:12, Andreas Perstinger  wrote:

> Sayan Chatterjee  wrote:
>
> >I know this error occurs when one tries to multiply a string with a
> >fraction i.e float. In my case , I can't figure out how can a numpy
> >floating point array be a string.
>
> The problem is not that the numpy array is a string but that you append
> the array to a python list:
>
> >  pv_za=[]
> >  pv_za.append(-K*np.sin(K*pv_za_temp))
> >  pv_za_temp = []
> >  pv_za_temp.append(np.array(pv_za))
>
> Both "pv_za" and "pv_za_temp" are python lists to which you append a
> numpy array. But since you delete both lists in each iteration I assume
> you want to just assign a new numpy array to both names:
>
> pv_za = -K * np.sin(K * pv_za_temp)
> pv_za_temp = pv_za # "pv_za" is already a numpy array
>
> Bye, Andreas
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 


--
*Sayan  Chatterjee*
Dept. of Physics and Meteorology
IIT Kharagpur
Lal Bahadur Shastry Hall of Residence
Room AB 205
Mob: +91 9874513565
blog: www.blissprofound.blogspot.com

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