Looking for Python Developers for MNC Client based at Bangalore

2012-12-31 Thread vani...@bharatheadhunters.com
Requirement : Python Developer 
Work Location:Bangalore
Experience: 5-8yrs  

  
Skill Set:
1.  Excellent Python and C Programming skills
2.  Good understanding of web based protocols i.e. HTTP/REST and other web 
services.
3.  Good understanding of XML and JSON
4.  Domain Knowledge of Wireless LAN(802.11) 
5.  Good understanding of client/server architecture
6.  Socket programming using TCP/UDP in C and Python
7.  Good understanding of Linux and Windows Operating Systems

Interested resumes send updated resume to vani...@bharatheadhunters.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tarfile and usernames

2012-12-31 Thread lars
On Sun, Dec 30, 2012 at 03:07:05PM -0500, Albert Hopkins wrote:
> > I can't see documented anywhere what this library does with userids and
> > groupids.  I can't guarantee that the computers involved will have the
> > same users and groups, and would like the archives to be extracted so
> > that the files are all owned by the extracting user.

> However, it should be stated that by default (on *nix anyway) if the
> user is not root then user/groups are assigned to the user exctracting
> the file (because only root can assign userids/non-member-groups).
> The TarFile extract*() methods pretty much inherit the same behavior as
> the *nix tar command.  So if you are extracting as a non-root user, you
> should expect the same behavoir.  If you are extracting as root but
> don't want to change user/groups may have to extract it manually or
> create your own class by inheriting TarFile and overriding the .chown()
> method.

Please take a look at the second example in the Examples section of the tarfile
docs:

http://docs.python.org/2.7/library/tarfile.html#examples

It shows how to extract a subset of an archive using a generator as some kind
of filter for the extractall() method. Just rewrite the example so that every
tarinfo is patched with the required user and group name information before
being yielded:

def filter(members):
for tarinfo in members:
tarinfo.uname = "root"
tarinfo.gname = "root"
yield tarinfo

That's it.

-- 
Lars Gustäbel
l...@gustaebel.de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: father class name

2012-12-31 Thread Ben Finney
Chris Rebert  writes:

> By contrast, in the first part of the *expression*
> `haha(object).theprint()`, you passed an argument (namely, `object`).
> Since __init__() wasn't expecting any arguments whatsoever, you
> therefore got an error.

Why is everyone talking about the initialiser, ‘__init__’?

When:

>  haha(object).theprint()
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > TypeError: object.__new__() takes no parameters

The error is talking about the constructor, ‘__new__’.

-- 
 \  “It's dangerous to be right when the government is wrong.” |
  `\   —Francois Marie Arouet Voltaire |
_o__)  |
Ben Finney

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


Re: father class name

2012-12-31 Thread Chris Rebert
On Mon, Dec 31, 2012 at 1:23 AM, Ben Finney  wrote:
> Chris Rebert  writes:
>
>> By contrast, in the first part of the *expression*
>> `haha(object).theprint()`, you passed an argument (namely, `object`).
>> Since __init__() wasn't expecting any arguments whatsoever, you
>> therefore got an error.
>
> Why is everyone talking about the initialiser, ‘__init__’?
>
> When:
>
>>  haha(object).theprint()
>> > Traceback (most recent call last):
>> >   File "", line 1, in 
>> > TypeError: object.__new__() takes no parameters
>
> The error is talking about the constructor, ‘__new__’.

Because the difference between the two (and indeed, the very purpose
of the latter) is a topic of intermediate/advanced difficulty, and the
OP appears to be a newbie.
As I stated, but your quotation omitted:
>> Note: I'm oversimplifying things a bit for the sake of understandability.

Cheers,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Question about nested loop

2012-12-31 Thread Isaac Won
Hi all,
I am a very novice for Python. Currently, I am trying to read continuous 
columns repeatedly in the form of array. 
my code is like below:

import numpy as np

b = []


c = 4
f = open("text.file", "r")


while c < 10:
c = c + 1

for  columns in ( raw.strip().split() for raw in f ):


b.append(columns[c])

y = np.array(b, float)
print c, y


I thought that  can get the arrays of the columns[5] to [10], but I only could 
get repetition of same arrays of columns[5].

The result was something like:

5 [1 2 3 4 .., 10 9 8]
6 [1 2 3 4 .., 10 9 8]
7 [1 2 3 4 .., 10 9 8]
8 [1 2 3 4 .., 10 9 8]
9 [1 2 3 4 .., 10 9 8]
10 [1 2 3 4 .., 10 9 8]


What I can't understand is that even though c increased incrementally upto 10, 
y arrays stay same.

Would someone help me to understand this problem more?

I really appreciate any help.

Thank you,

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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-31 Thread Adam Tauno Williams
On Thu, 2012-12-27 at 12:01 -0800, mogul wrote:
> 'Aloha!
> I'm new to python, got 10-20 years perl and C experience, all gained
> on unix alike machines hacking happily in vi, and later on in vim.
> Now it's python, and currently mainly on my kubuntu desktop.
> Do I really need a real IDE, as the windows guys around me say I do,

You don't need one.

You are crazy if you don't WANT one.

Check out geany 

-- 
Adam Tauno Williams 

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


Re: Question about nested loop

2012-12-31 Thread Gisle Vanem

"Isaac Won"  wrote:


while c < 10:
   c = c + 1

   for  columns in ( raw.strip().split() for raw in f ):


   b.append(columns[c])

   y = np.array(b, float)
   print c, y


I thought that  can get the arrays of the columns[5] to [10],
but I only could get repetition of same arrays of columns[5].


I don't pretend to know list comprehension very well, but 
'c' isn't incremented in the inner loop ( .. for raw in f). 
Hence you only append to columns[5].


Maybe you could use another 'd' indexer inside the inner-loop?
But there must a more elegant way to solve your issue. (I'm a
PyCommer myself).

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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-31 Thread Hans Mulder
On 31/12/12 12:57:59, Adam Tauno Williams wrote:
> On Thu, 2012-12-27 at 12:01 -0800, mogul wrote:
>> 'Aloha!
>> I'm new to python, got 10-20 years perl and C experience, all gained
>> on unix alike machines hacking happily in vi, and later on in vim.
>> Now it's python, and currently mainly on my kubuntu desktop.
>> Do I really need a real IDE, as the windows guys around me say I do,
> 
> You don't need one.

+1

> You are crazy if you don't WANT one.

ITYM: you'd be crazy if you'd want one.

> Check out geany 

Don't bother: Python comes with a free IDE named IDLE.  Try it
for a few minutes, and you'll find that most of the features
that make vim so wonderful, are missing from IDLE.

Just stay with vim.

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


Re: Question about nested loop

2012-12-31 Thread Hans Mulder
On 31/12/12 11:02:56, Isaac Won wrote:
> Hi all,
> I am a very novice for Python. Currently, I am trying to read continuous
> columns repeatedly in the form of array. 
> my code is like below:
> 
> import numpy as np
> 
> b = [] 
> c = 4
> f = open("text.file", "r")
> 
> while c < 10:
> c = c + 1
> 
> for  columns in ( raw.strip().split() for raw in f ):
> b.append(columns[c])
> 
> y = np.array(b, float)
> print c, y
> 
> 
> I thought that  can get the arrays of the columns[5] to [10], but I only
> could get repetition of same arrays of columns[5].
> 
> The result was something like:
> 
> 5 [1 2 3 4 .., 10 9 8]
> 6 [1 2 3 4 .., 10 9 8]
> 7 [1 2 3 4 .., 10 9 8]
> 8 [1 2 3 4 .., 10 9 8]
> 9 [1 2 3 4 .., 10 9 8]
> 10 [1 2 3 4 .., 10 9 8]
> 
> 
> What I can't understand is that even though c increased incrementally upto 10,
> y arrays stay same.
> 
> Would someone help me to understand this problem more?

That's because the inner loop read from a file until his reaches
the end of the file.  Since you're not resetting the file pointer,
during the second and later runs of the outer loop, the inner loop
starts at the end of the file and terminates without any action.

You'd get more interesting results if you rewind the file:

import numpy as np

b = []
c = 4
f = open("text.file", "r")

while c < 10:
c = c + 1

f.seek(0,0)
for  columns in ( raw.strip().split() for raw in f ):
b.append(columns[c])

y = np.array(b, float)
print c, y

It's a bit inefficient to read the same file several times.
You might consider reading it just once.  For example:

import numpy as np

b = []

f = open("text.file", "r")
data = [ line.strip().split() for line in f ]
f.close()

for c in xrange(5, 11):
for row in data:
b.append(row[c])

y = np.array(b, float)
print c, y


Hope this helps,

-- HansM



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


Python is awesome (Project Euler)

2012-12-31 Thread Roy Smith
If you haven't heard of it, you should check out Project Euler 
(http://projecteuler.net/).  It's a series of (currently) 408 
math-oriented programming problems, of varying degrees of difficulty.

The tie-in to this group is just how many of them are trivial in Python.  
There's a whole slew of them which become one-liners due to Python's 
long int support.  For example, http://projecteuler.net/problem=48.  
Datetime made me feel like I was cheating when I did 
http://projecteuler.net/problem=19.

When you work with something as cool as Python every day, sometimes you 
lose sight of just how awesome it is.  Thanks to everybody who has 
worked to make Python possible.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python is awesome (Project Euler)

2012-12-31 Thread Alex
Yes. Although sometimes I fear that we are becoming a society of
end-users who rely too much on the capability of our tools and fail to
take the time to understand the fundamentals upon which those tools are
based or cultivate the problem-solving skills that Project Euler
appears to be trying to hone.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python is awesome (Project Euler)

2012-12-31 Thread Grant Edwards
On 2012-12-31, Alex  wrote:

> Yes. Although sometimes I fear that we are becoming a society of
> end-users who rely too much on the capability of our tools and fail to
> take the time to understand the fundamentals upon which those tools are
> based or cultivate the problem-solving skills that Project Euler
> appears to be trying to hone.

That's probably pretty much what somebody said 10K years ago when
people started to specialize in different occupations and hunters
started getting their spear-points by bartering for them with dried
meat instead of everybody flaking their own out of chunks of flint.

-- 
Grant Edwards   grant.b.edwardsYow! Being a BALD HERO
  at   is almost as FESTIVE as a
  gmail.comTATTOOED KNOCKWURST.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python is awesome (Project Euler)

2012-12-31 Thread Roy Smith
In article , "Alex"  
wrote:

> Yes. Although sometimes I fear that we are becoming a society of
> end-users who rely too much on the capability of our tools and fail to
> take the time to understand the fundamentals upon which those tools are
> based or cultivate the problem-solving skills that Project Euler
> appears to be trying to hone.

Over the years, my understanding of the fundamentals of computing has 
included C, assembler, microcoding, TTL logic design, transistor 
circuits, and a bit of semiconductor physics.

I could certainly build you a full-adder or a flip-flop from a pile of 
NAND gates.  I *think* I could probably cobble together a NAND gate from 
a pile of transistors (but I know I couldn't build a transistor from a 
pile of sand).  I'm very happy living at the top of the stack these days 
:-)

I guess the question is, what *is* a "fundamental"?  There's lots of 
stuff in Project Euler that is about picking the right algorithm.  
There's even a pair of problems which are exactly the same problem, 
except that one has a (much) larger data set.  You can solve the first 
with brute-force, but not the second.  Algorithms will always be 
fundamental.

But, is knowing how to do arbitrary precision arithmetic a fundamental?  
I don't think so.  Back with I started working with microprocessors, 
knowing how to do multi-precision addition was essential because you 
only had an 8-bit adder.  But those days are long gone.

There's a problem I just worked where you need to find the last 10 
digits of some million-digit prime.  Python's long ints don't help you 
there.  What does help you is figuring out a way to solve the problem 
that's not brute-force.  I think that's what Euler is all about.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to output to syslog before /dev/log exists?

2012-12-31 Thread yanegomi
Basically I'm trying to write a snippet of code that outputs to both syslog 
and the console at boot on a FreeBSD box, and I'm not 100% sure how to direct 
the SysLogHandler to use the dmesg buffer instead of trying to use either 
localhost:514 (and failing silently), or use /dev/log (and throwing an 
Exception at boot). Here's an example of what I was trying to use:

import logging
import logging.handlers

# ...

LOG_FORMAT = '<%(name)s> %(message)s'
logging.basicConfig(format=LOG_FORMAT)
logger = logging.getLogger('root')
slh = logging.handlers.SysLogHandler(address='/dev/log') # XXX: Does not work 
if /dev/log doesn't exist -- for obvious reasons.
slh.setFormatter(logging.Formatter(fmt=LOG_FORMAT))
logger.addHandler(slh)

Hints within documentation is welcome and appreciated (the terms that 
needed to be looked for on Google are failing me right now :)..).
Thanks!
-Garrett
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about nested loop

2012-12-31 Thread Isaac Won
On Monday, December 31, 2012 5:25:16 AM UTC-6, Gisle Vanem wrote:
> "Isaac Won"  wrote:
> 
> 
> 
> > while c < 10:
> 
> >c = c + 1
> 
> > 
> 
> >for  columns in ( raw.strip().split() for raw in f ):
> 
> > 
> 
> > 
> 
> >b.append(columns[c])
> 
> > 
> 
> >y = np.array(b, float)
> 
> >print c, y
> 
> > 
> 
> > 
> 
> > I thought that  can get the arrays of the columns[5] to [10],
> 
> > but I only could get repetition of same arrays of columns[5].
> 
> 
> 
> I don't pretend to know list comprehension very well, but 
> 
> 'c' isn't incremented in the inner loop ( .. for raw in f). 
> 
> Hence you only append to columns[5].
> 
> 
> 
> Maybe you could use another 'd' indexer inside the inner-loop?
> 
> But there must a more elegant way to solve your issue. (I'm a
> 
> PyCommer myself).
> 
> 
> 
> --gv

Thank you for your advice.
 I agree with you and tried to increment in inner loop, but still not very 
succesful. Anyway many thanks for you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about nested loop

2012-12-31 Thread Isaac Won
On Monday, December 31, 2012 6:59:34 AM UTC-6, Hans Mulder wrote:
> On 31/12/12 11:02:56, Isaac Won wrote:
> 
> > Hi all,
> 
> > I am a very novice for Python. Currently, I am trying to read continuous
> 
> > columns repeatedly in the form of array. 
> 
> > my code is like below:
> 
> > 
> 
> > import numpy as np
> 
> > 
> 
> > b = [] 
> 
> > c = 4
> 
> > f = open("text.file", "r")
> 
> > 
> 
> > while c < 10:
> 
> > c = c + 1
> 
> > 
> 
> > for  columns in ( raw.strip().split() for raw in f ):
> 
> > b.append(columns[c])
> 
> > 
> 
> > y = np.array(b, float)
> 
> > print c, y
> 
> > 
> 
> > 
> 
> > I thought that  can get the arrays of the columns[5] to [10], but I only
> 
> > could get repetition of same arrays of columns[5].
> 
> > 
> 
> > The result was something like:
> 
> > 
> 
> > 5 [1 2 3 4 .., 10 9 8]
> 
> > 6 [1 2 3 4 .., 10 9 8]
> 
> > 7 [1 2 3 4 .., 10 9 8]
> 
> > 8 [1 2 3 4 .., 10 9 8]
> 
> > 9 [1 2 3 4 .., 10 9 8]
> 
> > 10 [1 2 3 4 .., 10 9 8]
> 
> > 
> 
> > 
> 
> > What I can't understand is that even though c increased incrementally upto 
> > 10,
> 
> > y arrays stay same.
> 
> > 
> 
> > Would someone help me to understand this problem more?
> 
> 
> 
> That's because the inner loop read from a file until his reaches
> 
> the end of the file.  Since you're not resetting the file pointer,
> 
> during the second and later runs of the outer loop, the inner loop
> 
> starts at the end of the file and terminates without any action.
> 
> 
> 
> You'd get more interesting results if you rewind the file:
> 
> 
> 
> import numpy as np
> 
> 
> 
> b = []
> 
> c = 4
> 
> f = open("text.file", "r")
> 
> 
> 
> while c < 10:
> 
> c = c + 1
> 
> 
> 
> f.seek(0,0)
> 
> for  columns in ( raw.strip().split() for raw in f ):
> 
> b.append(columns[c])
> 
> 
> 
> y = np.array(b, float)
> 
> print c, y
> 
> 
> 
> It's a bit inefficient to read the same file several times.
> 
> You might consider reading it just once.  For example:
> 
> 
> 
> import numpy as np
> 
> 
> 
> b = []
> 
> 
> 
> f = open("text.file", "r")
> 
> data = [ line.strip().split() for line in f ]
> 
> f.close()
> 
> 
> 
> for c in xrange(5, 11):
> 
> for row in data:
> 
> b.append(row[c])
> 
> 
> 
> y = np.array(b, float)
> 
> print c, y
> 
> 
> 
> 
> 
> Hope this helps,
> 
> 
> 
> -- HansM

Hi Hans,

I appreciate your advice and kind tips.

The both codes which you gave seem pretty interesting.

Both look working for incrementing inner loop number, but the results of y are 
added repeatedly such as [1,2,3],[1,2,3,4,5,6], [1,2,3,4,5,6,7,8,9]. Anyhow, 
really thank you for your help and I will look at this problem more in detail.

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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-31 Thread Ben Finney
Hans Mulder  writes:

> Don't bother: Python comes with a free IDE named IDLE.

And any decent Unix-alike (most OSen apart from Windows) comes with its
own IDE: the shell, a good text editor (Vim or Emacs being the primary
candidates), and a terminal multiplexor (such as ‘tmux’ or GNU Screen).

Learning to use that development environment will benefit you far more
than any language-specific tool.

-- 
 \   “I bought some powdered water, but I don't know what to add.” |
  `\—Steven Wright |
_o__)  |
Ben Finney

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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-31 Thread Chris Angelico
On Tue, Jan 1, 2013 at 9:46 AM, Ben Finney  wrote:
> Hans Mulder  writes:
>
>> Don't bother: Python comes with a free IDE named IDLE.
>
> And any decent Unix-alike (most OSen apart from Windows) comes with its
> own IDE: the shell, a good text editor (Vim or Emacs being the primary
> candidates), and a terminal multiplexor (such as ‘tmux’ or GNU Screen).
>
> Learning to use that development environment will benefit you far more
> than any language-specific tool.

And more than that: Learning to use that development environment gives
you the flexibility to swap out components individually. "The shell"
could be one of several (though bash seems to be the most popular),
the editor is one of many, and there are a good few options for
terminal arrangement (tmux, screen, gnome-terminal, etc). So what if
you decide you don't like vim OR emacs - you can still use the "Unix
IDE" with some other editor. Most IDEs don't have that facility.

It's a question of freedom. Would you let someone else choose what
shoes you're allowed to wear? Then why cede over the choice of
development software? No matter how awesome those shoes are, it's an
unnecessary restriction in freedom.

Of course, you're free to use an IDE if you want to, too. I don't see
much point in it, but if that's how you swing, go for it.

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


Considering taking a hammer to the computer...

2012-12-31 Thread worldsbiggestsabresfan
Hey :) 

I'm trying to help my son with an assignment and spending hours making an inch 
of progress.  I know nothing about programming and I'm trying to learn, on my 
own, at a rate faster than possible. I would love a little help!

My son is taking an introductory course and his assignment is to use the loops 
for and while to create a program which calculates a hotel's occupancy rate. He 
has managed all of the "inputs" but needs help with the following:

1) The first question asked is how many floors are in the hotel - and then the 
questions are asked floor by floor.  We can't figure out how to get the program 
to stop questioning when the number of floors is reached.

2) He has programmed specific calculations for each floor, and now needs to 
have  calculations for the entire hotel based on the input about each floor.

Here is what he has done so far:


#This program will calculate the occupancy rate of a hotel
floor_number = 0


number_of_floors = int(input("How many floors are in the hotel?: "))
while number_of_floors < 1:
print ("Invalid input!") 
number_of_floors = input("Enter the number of floors in the hotel: ") 
while number_of_floors > 1:
floor_number = floor_number + 1
print()
print ("For floor #",floor_number) 
rooms_on_floor = int(input("How many rooms are on the floor ?: " ))
while rooms_on_floor < 10:
print ("Invalid input!") 
rooms_on_floor = int(input("Enter the number of rooms on floor: "))

occupied_rooms = int(input("How many rooms on the floor are occupied?: "))

#CALCULATE OCCUPANCY RATE FOR FLOOR
occupancy_rate = occupied_rooms / rooms_on_floor
print ("The occupancy rate for this floor is ",occupancy_rate)



The following is what we believe needs to go in the program at the end except 
we can't figure out how to calculate it and make it all work :/ (alot of the 
terms have nothing at all to identify them yet...) 

hotel_occupancy = total_occupied / total_rooms
print ("The occupancy rate for this hotel is ",hotel_occupancy)
print ("The total number of rooms at this hotel is ",total_rooms)
print ("The number of occupied rooms at this hotel is ",total_occupied)
vacant_rooms = total_rooms - total_occupied
print ("The number of vacant rooms at this hotel is ",vacant_rooms)

We've searched and read and we found things about the "break" and "pass" 
commands but his teacher will not allow them because they haven't been taught 
yet.  

If you have any ideas and can take a minute to help, that would be great :)

Thank you!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Considering taking a hammer to the computer...

2012-12-31 Thread Chris Angelico
On Tue, Jan 1, 2013 at 10:42 AM,   wrote:
> while number_of_floors > 1:
> floor_number = floor_number + 1
> print()
> print ("For floor #",floor_number)
> rooms_on_floor = int(input("How many rooms are on the floor ?: " ))
> while rooms_on_floor < 10:
> print ("Invalid input!")
> rooms_on_floor = int(input("Enter the number of rooms on floor: "))

You have a loop here that can never terminate, because
number_of_floors never changes.

There are a couple of solutions to this. One would be to compare
floor_number to number_of_floors, and stop the loop once the one
exceeds the other; another (and more Pythonic) way would be to use a
'for' loop, and iterate over the range of numbers from 1 to the number
of floors. See if your son has learned about range(), if so he should
be able to figure it out from that clue.

One tip: When you're asking a question like this, mention what Python
version you're using. I'm guessing it's Python 3.something, but that
might not be right. If it is indeed Python 3, then the repeated
question here will be a problem:

number_of_floors = int(input("How many floors are in the hotel?: "))
while number_of_floors < 1:
print ("Invalid input!")
number_of_floors = input("Enter the number of floors in the hotel: ")

Note the difference between the two request lines (other than the
prompt, which is insignificant). The second time around, you're not
turning it into an integer, so that will crash (in Python 3) with the
error that strings and integers aren't ordered (that is, that it makes
no sense to ask whether a string is less than the integer 1). Python
2, on the other hand, will behave very differently here, as input()
has a quite different meaning (and one that you almost certainly do
NOT want).

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


Re: Considering taking a hammer to the computer...

2012-12-31 Thread Chris Angelico
On Tue, Jan 1, 2013 at 10:42 AM,   wrote:
> Hey :)

Oh, and another tip. Threatening violence to your computer is unlikely
to make it change its ways, and it certainly isn't a helpful subject
line :)

All the best.

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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-31 Thread xDog Walker
On Monday 2012 December 31 14:46, Ben Finney wrote:
> “I bought some powdered water, but I don't know what to add.”

Suggest to Stephen Wright to add hot coffee.

-- 
Yonder nor sorghum stenches shut ladle gulls stopper torque wet 
strainers.

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


Re: Considering taking a hammer to the computer...

2012-12-31 Thread Mitya Sirenef

On 12/31/2012 06:42 PM, worldsbiggestsabres...@gmail.com wrote:

Hey :)

>
> I'm trying to help my son with an assignment and spending hours 
making an inch of progress. I know nothing about programming and I'm 
trying to learn, on my own, at a rate faster than possible. I would love 
a little help!

>
> My son is taking an introductory course and his assignment is to use 
the loops for and while to create a program which calculates a hotel's 
occupancy rate. He has managed all of the "inputs" but needs help with 
the following:

>
> 1) The first question asked is how many floors are in the hotel - and 
then the questions are asked floor by floor. We can't figure out how to 
get the program to stop questioning when the number of floors is reached.

>
> 2) He has programmed specific calculations for each floor, and now 
needs to have calculations for the entire hotel based on the input about 
each floor.

>
>
> Here is what he has done so far:
>
>
> #This program will calculate the occupancy rate of a hotel
> floor_number = 0
>
>
> number_of_floors = int(input("How many floors are in the hotel?: "))
> while number_of_floors < 1:
> print ("Invalid input!")
> number_of_floors = input("Enter the number of floors in the hotel: ")
> while number_of_floors > 1:
> floor_number = floor_number + 1
> print()
> print ("For floor #",floor_number)
> rooms_on_floor = int(input("How many rooms are on the floor ?: " ))
> while rooms_on_floor < 10:
> print ("Invalid input!")
> rooms_on_floor = int(input("Enter the number of rooms on floor: "))
>
> occupied_rooms = int(input("How many rooms on the floor are 
occupied?: "))

>
> #CALCULATE OCCUPANCY RATE FOR FLOOR
> occupancy_rate = occupied_rooms / rooms_on_floor
> print ("The occupancy rate for this floor is ",occupancy_rate)
>
>
>
> The following is what we believe needs to go in the program at the 
end except we can't figure out how to calculate it and make it all work 
:/ (alot of the terms have nothing at all to identify them yet...)

>
> hotel_occupancy = total_occupied / total_rooms
> print ("The occupancy rate for this hotel is ",hotel_occupancy)
> print ("The total number of rooms at this hotel is ",total_rooms)
> print ("The number of occupied rooms at this hotel is ",total_occupied)
> vacant_rooms = total_rooms - total_occupied
> print ("The number of vacant rooms at this hotel is ",vacant_rooms)
>
> We've searched and read and we found things about the "break" and 
"pass" commands but his teacher will not allow them because they haven't 
been taught yet.

>
> If you have any ideas and can take a minute to help, that would be 
great :)

>
> Thank you!


Hi! First I want to note that this task would be easier and better to do
with a break statement, so it's quite unfortunate that the teacher did
not cover the right tools (and very basic ones, in fact) and yet given
this task.

Another question: are you allowed to use functions? (I'm guessing not).

You can do this task much easier if you write it out in pseudo code
before you go to python code. For example, to convert your existing
code to pseudo code:

* set floor_number to 0
* get number of floors from the user

* as long as number of floors is less than 1:
* print invalid input
* get number of floors from the user

* as long as number of floors is more than 1:
* increment floor_number

* get number of rooms
* as long as number of rooms is less than 10:
* get number of rooms

* get occupied_rooms
* occupancy_rate = occupied rooms / number of rooms

* how do we keep track of total rooms and total occupied rooms here??


Does it make it easier to think about the logic of the program?

 - mitya



--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


Re: Considering taking a hammer to the computer...

2012-12-31 Thread Mitya Sirenef

On 12/31/2012 07:29 PM, Mitya Sirenef wrote:



Hi! First I want to note that this task would be easier and better to do
with a break statement, so it's quite unfortunate that the teacher did
not cover the right tools (and very basic ones, in fact) and yet given
this task.

Another question: are you allowed to use functions? (I'm guessing not).

You can do this task much easier if you write it out in pseudo code
before you go to python code. For example, to convert your existing
code to pseudo code:

* set floor_number to 0
* get number of floors from the user

* as long as number of floors is less than 1:
* print invalid input
* get number of floors from the user

* as long as number of floors is more than 1:
* increment floor_number

* get number of rooms
* as long as number of rooms is less than 10:
* get number of rooms

* get occupied_rooms
* occupancy_rate = occupied rooms / number of rooms

* how do we keep track of total rooms and total occupied rooms here??


Does it make it easier to think about the logic of the program?

 - mitya




I forgot to add this:

question = "How many floors are in the hotel?: "
number_of_floors = int(input(question))

while number_of_floors < 1:
print("Invalid input!")
number_of_floors = int(input(question))


It's easier to save the question in a variable and use it two
times (and do the same in the next loop); it's not clear
why/if the questions should be different as you're asking
the user for the same thing.

 -m

--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


Re: Considering taking a hammer to the computer...

2012-12-31 Thread Vlastimil Brom
2013/1/1  :
> Hey :)
>
> I'm trying to help my son with an assignment and spending hours making an 
> inch of progress.  I know nothing about programming and I'm trying to learn, 
> on my own, at a rate faster than possible. I would love a little help!
>
> My son is taking an introductory course and his assignment is to use the 
> loops for and while to create a program which calculates a hotel's occupancy 
> rate. He has managed all of the "inputs" but needs help with the following:
>
> 1) The first question asked is how many floors are in the hotel - and then 
> the questions are asked floor by floor.  We can't figure out how to get the 
> program to stop questioning when the number of floors is reached.
>
> 2) He has programmed specific calculations for each floor, and now needs to 
> have  calculations for the entire hotel based on the input about each floor.
>
> Here is what he has done so far:
>
>
> #This program will calculate the occupancy rate of a hotel
> floor_number = 0
>
>
> number_of_floors = int(input("How many floors are in the hotel?: "))
> while number_of_floors < 1:
> print ("Invalid input!")
> number_of_floors = input("Enter the number of floors in the hotel: ")
> while number_of_floors > 1:
> floor_number = floor_number + 1
> print()
> print ("For floor #",floor_number)
> rooms_on_floor = int(input("How many rooms are on the floor ?: " ))
> while rooms_on_floor < 10:
> print ("Invalid input!")
> rooms_on_floor = int(input("Enter the number of rooms on floor: "))
>
> occupied_rooms = int(input("How many rooms on the floor are occupied?: "))
>
> #CALCULATE OCCUPANCY RATE FOR FLOOR
> occupancy_rate = occupied_rooms / rooms_on_floor
> print ("The occupancy rate for this floor is ",occupancy_rate)
>
>
>
> The following is what we believe needs to go in the program at the end except 
> we can't figure out how to calculate it and make it all work :/ (alot of the 
> terms have nothing at all to identify them yet...)
>
> hotel_occupancy = total_occupied / total_rooms
> print ("The occupancy rate for this hotel is ",hotel_occupancy)
> print ("The total number of rooms at this hotel is ",total_rooms)
> print ("The number of occupied rooms at this hotel is ",total_occupied)
> vacant_rooms = total_rooms - total_occupied
> print ("The number of vacant rooms at this hotel is ",vacant_rooms)
>
> We've searched and read and we found things about the "break" and "pass" 
> commands but his teacher will not allow them because they haven't been taught 
> yet.
>
> If you have any ideas and can take a minute to help, that would be great :)
>
> Thank you!
> --
> http://mail.python.org/mailman/listinfo/python-list

Hi,
if "break" isn't allowed, you can add the appropriate condition to the
while construct
>>> i=0
>>> while i < 4:
... print i
... i = i + 1
...
0
1
2
3
>>>

or you can use the for-loops based on the previously determined number
of the floors and rooms respectively.
let's hope "range(...)" is allowed - the usual idiom is e.g.:
>>> for i in range(4):
... print i
...
0
1
2
3
>>>

Note, that the indexing in python is zero-based (which also applies
for range by default); the range doesn't include the given upper
stop-value
http://docs.python.org/release/3.3.0/library/stdtypes.html#range

Depending on the assignment and on the interpretation of the
ground-floor ("zeroth-floor"), you may need to account for this (you
can also pass the "start" value to range(...) ).

the totals can be collected simply by incrementing the respective
numbers with each floor within the loop.

hth,
  vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WWE Divas Nude, plus Nude Diva & full open video, lita, mickey & more....

2012-12-31 Thread wesbass2013
On Sunday, May 3, 2009 5:37:33 AM UTC-7, Mickey wrote:
> Wwe,World Wrestling Entertainment,WWE Smackdow,WWE RAW,WWE Divas,WWE
> Divas Nude, plus Nude Diva Wallpaper and WWE Nude Diva Screensavers,&
> full open video,lita,mickey & more
> http://www.earningzones.com/wwe_divas

thats would be great
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Considering taking a hammer to the computer...

2012-12-31 Thread worldsbiggestsabresfan
Here is what I've learned:

1) There's a bunch of extremely helpful and wonderful people here.

2) There's a bunch of very intelligent people here.

3) I still don't have any idea what I'm doing.

4) It's New Year's Eve and I'm trying to learn Python...?  

I'm going to read all of this over and over until it makes sense to me!  Thank 
you all SO MUCH!!!  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Considering taking a hammer to the computer...

2012-12-31 Thread Mitya Sirenef

On 12/31/2012 08:30 PM, worldsbiggestsabres...@gmail.com wrote:

Here is what I've learned:

1) There's a bunch of extremely helpful and wonderful people here.

2) There's a bunch of very intelligent people here.

3) I still don't have any idea what I'm doing.

4) It's New Year's Eve and I'm trying to learn Python...?

I'm going to read all of this over and over until it makes sense to me!  Thank 
you all SO MUCH!!!



You're welcome and don't hesitate to ask follow-up question,
Happy new year!

 - mitya


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


Re: dict comprehension question.

2012-12-31 Thread Steven D'Aprano
On Sat, 29 Dec 2012 18:56:57 -0500, Terry Reedy wrote:

> On 12/29/2012 2:48 PM, Quint Rankid wrote:
> 
>> Given a list like:
>> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
>> I would like to be able to do the following as a dict comprehension. 
>> a = {}
>> for x in w:
>>  a[x] = a.get(x,0) + 1
>> results in a having the value:
>> {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}
> 
> Let me paraphrase this: "I have nice, clear, straightforward,
> *comprehensible* code that I want to turn into an incomprehensible mess
> with a 'comprehension." That is the ironic allure of comprehensions.

But... but... one liner! ONE LINNR Won't somebody think 
of the lines I'll save

*wink*


In case it's not obvious, I'm 100% agreeing with Terry here. List comps 
and dict comps are wonderful things, but they can't do everything, and 
very often even if they can do something they shouldn't because it makes 
the code inefficient or unreadable.

There's nothing wrong with a two or three liner.



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


Re: father class name

2012-12-31 Thread Steven D'Aprano
On Mon, 31 Dec 2012 20:23:44 +1100, Ben Finney wrote:

> Chris Rebert  writes:
> 
>> By contrast, in the first part of the *expression*
>> `haha(object).theprint()`, you passed an argument (namely, `object`).
>> Since __init__() wasn't expecting any arguments whatsoever, you
>> therefore got an error.
> 
> Why is everyone talking about the initialiser, ‘__init__’?
> 
> When:
> 
>>  haha(object).theprint()
>> > Traceback (most recent call last):
>> >   File "", line 1, in 
>> > TypeError: object.__new__() takes no parameters
> 
> The error is talking about the constructor, ‘__new__’.


Good point.

I think we do a disservice to newbies when we (inadvertently) discourage 
them from reading the tracebacks generated by an error. The traceback 
clearly talks about a __new__ method.

I don't believe that talking about the constructor __new__ is so 
complicated that we should ignore the actual error and go of on a wild-
goose chase about the initialiser __init__, especially since adding an 
__init__ method to the class *won't solve the problem*.

Sorry Chris, I think you dropped the ball on this one and gave an overtly 
misleading answer :-(



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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-31 Thread Steven D'Aprano
On Sat, 29 Dec 2012 14:00:23 -0500, Mitya Sirenef wrote:

> I think the general idea is that with editors like Vim you don't get
> distracted by having to do some kind of an editor task, letting you keep
> your full attention on the code logic. For instance, if I need to change
> a block inside parens, I type ci) (stands for change inside parens),
> while with a regular editor I'd have to do it manually and by the time
> I'm done, I'd forget the bigger picture of what I'm doing with the code.

See, by the time I remembered what obscure (to me) command to type, or 
searched the help files and the Internet, I'd have forgotten what the 
hell it was I was trying to do. Well, almost. My memory is not quite that 
bad, but it would certainly be a much bigger disruption to my coding than 
just doing the edit by hand.

I do love the power of command line tools, but I think that for rich 
applications like editors, the interface is so clunky that I'd rather use 
a less-powerful editor, and do more editing manually, than try to 
memorize "hundreds" of commands.

With a GUI app, I can run the mouse over the menus and see a high-level 
overview of everything the app can do in a matter of a second or two. 
(Perhaps three or five seconds if the app over-uses hierarchical menus.) 
But with a text interface, commands are much less discoverable. I can 
also use *spacial* memory to zero in on commands much more easily than 
verbal memory -- I have no idea whether the command I want is called 
"Spam" or "Ham" or "Tinned Bully Beef", but I know it's in the top 
quarter of the "Lunch" menu, and I will recognise it when I see it.

On the other hand, it's a lot harder to use a GUI app over a slow SSH 
connection to a remote machine in a foreign country over a flaky link 
than it is to use a command line or text-interface app.


> Another example: >ap stands for "indent a paragraph (separated by blank
> lines)". And there are many dozens if not hundreds such commands that
> let you stay focused on the logic of your code.

Ah yes, the famous "a for indent" mnemonic. *wink*


> The trade-off, of course, is that you have to remember all (or most) of
> the commands, but I figured if I spend the next 20-30+ years programming
> in some version of Vim, it's well worth the initial investment.
> 
> By the way, to help me remember the commands, I wrote a small script
> that lets me type in a few characters of a command or its description
> and filters out the list of matching commands. It really helps,
> especially when I change a lot of my mappings.

It seems to me, that by the time I would have searched for the right 
command to use, decided which of the (multiple) matching commands is the 
right one, then used the command, it would have been quicker and less 
distracting to have just done the editing by hand. But now I'm just 
repeating myself.



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


Re: Considering taking a hammer to the computer...

2012-12-31 Thread Modulok
> I'm trying to help my son with an assignment and spending hours making an
> inch of progress.  I know nothing about programming and I'm trying to learn,
> on my own, at a rate faster than possible. I would love a little help!
>
> My son is taking an introductory course and his assignment is to use the
> loops for and while to create a program which calculates a hotel's occupancy
> rate. He has managed all of the "inputs" but needs help with the following:
>
> 1) The first question asked is how many floors are in the hotel - and then
> the questions are asked floor by floor.  We can't figure out how to get the
> program to stop questioning when the number of floors is reached.
>
> 2) He has programmed specific calculations for each floor, and now needs to
> have  calculations for the entire hotel based on the input about each
> floor.
>
> Here is what he has done so far:
>
>
> #This program will calculate the occupancy rate of a hotel
> floor_number = 0
>
>
> number_of_floors = int(input("How many floors are in the hotel?: "))
> while number_of_floors < 1:
> print ("Invalid input!")
> number_of_floors = input("Enter the number of floors in the hotel: ")
> while number_of_floors > 1:
> floor_number = floor_number + 1
> print()
> print ("For floor #",floor_number)
> rooms_on_floor = int(input("How many rooms are on the floor ?: " ))
> while rooms_on_floor < 10:
> print ("Invalid input!")
> rooms_on_floor = int(input("Enter the number of rooms on floor: "))
>
> occupied_rooms = int(input("How many rooms on the floor are occupied?:
> "))
>
> #CALCULATE OCCUPANCY RATE FOR FLOOR
> occupancy_rate = occupied_rooms / rooms_on_floor
> print ("The occupancy rate for this floor is ",occupancy_rate)
>
>
>
> The following is what we believe needs to go in the program at the end
> except we can't figure out how to calculate it and make it all work :/ (alot
> of the terms have nothing at all to identify them yet...)
>
> hotel_occupancy = total_occupied / total_rooms
> print ("The occupancy rate for this hotel is ",hotel_occupancy)
> print ("The total number of rooms at this hotel is ",total_rooms)
> print ("The number of occupied rooms at this hotel is ",total_occupied)
> vacant_rooms = total_rooms - total_occupied
> print ("The number of vacant rooms at this hotel is ",vacant_rooms)
>
> We've searched and read and we found things about the "break" and "pass"
> commands but his teacher will not allow them because they haven't been
> taught yet.
>
> If you have any ideas and can take a minute to help, that would be great :)
>
> Thank you!


Here's your program with some extra comments to get you started:

#This program will calculate the occupancy rate of a hotel
floor_number = 0


number_of_floors = int(input("How many floors are in the hotel?: "))
while number_of_floors < 1:
print ("Invalid input!")

number_of_floors = input("Enter the number of floors in the hotel: ")
# Remember you need to make sure this is an int, just like before.
# number_of_floors = int(input("Enter the number of floors
in the hotel: ")) Right now it's a string.


while number_of_floors > 1:
# This loop runs forever, as number_of_floors never changes. You need
# to do something to `number_of_floors` such as de-increment it e.g:
# `number_of_floors -= 1`, that way we will *eventually* have
# number_of_floors less than 1, thus stopping the loop. A better
# idea would be to use a `for` loop instead of the above `while`
# loop. For example::
#
#   for i in range(number_of_floors):
#   # blah... do something for each floor. This loop
auto-terminates.
#

floor_number = floor_number + 1
print()
print ("For floor #",floor_number)
rooms_on_floor = int(input("How many rooms are on the floor ?: " ))

while rooms_on_floor < 10:
print ("Invalid input!")
# You might consider telling your user why their input is
# invalid. e.g: "rooms on floor must be greater than 10".

rooms_on_floor = int(input("Enter the number of rooms on floor: "))


occupied_rooms = int(input("How many rooms on the floor are
occupied?: "))

#CALCULATE OCCUPANCY RATE FOR FLOOR
occupancy_rate = occupied_rooms / rooms_on_floor
print ("The occupancy rate for this floor is ",occupancy_rate)


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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-31 Thread Steven D'Aprano
On Sun, 30 Dec 2012 09:30:10 +1100, Chris Angelico wrote:

> Absolutely! Though it's roughly as good to have the current cursor
> position shown in a status line somewhere, and takes up less real
> estate. But yes, vital to be able to see that. Even when I'm sitting
> *right next to* my boss and communicating verbally, I'll talk about the
> code by quoting line numbers. "Let me explain. (No, there is too much.
> Let me sum up.) Pull up foobar dot jay ess and go to line 254-ish - see
> how the frobnosticator always gets called with a quuxed argument?"

I call shenanigans :-P

I don't expect that you keep in your head the line numbers (even the line 
numbers-ish) of interesting or pertinent features of your code, 
*especially* while the code is in active development and the line numbers 
are rapidly changing. I think it is far more likely that you keep 
function, class or method names in your head (after all, you are 
presumably reading and writing those names very often), and when you want 
to demonstrate some feature, you *first* look it up by higher-level 
object ("let's see the frob_quux function") to get the line number.

Assuming that your functions and methods are not obnoxiously huge, I 
think having a good class browser which lets you jump directly to 
functions or methods is *far* more useful than line numbers, in this 
context.


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


Re: ignore case only for a part of the regex?

2012-12-31 Thread Steven D'Aprano
On Sun, 30 Dec 2012 10:20:19 -0500, Roy Smith wrote:

> The way I would typically do something like this is build my regexes in
> all lower case and .lower() the text I was matching against them.  I'm
> curious what you're doing where you want to enforce case sensitivity in
> one part of a header, but not in another.

Well, sometimes you have things that are case sensitive, and other things 
which are not, and sometimes you need to match them at the same time. I 
don't think this is any more unusual than (say) wanting to match an 
otherwise lowercase word whether or not it comes at the start of a 
sentence:

"[Pp]rogramming"

is conceptually equivalent to "match case-insensitive `p`, and case-
sensitive `rogramming`".


By the way, although there is probably nothing you can (easily) do about 
this prior to Python 3.3, converting to lowercase is not the right way to 
do case-insensitive matching. It happens to work correctly for ASCII, but 
it is not correct for all alphabetic characters.


py> 'Straße'.lower()
'straße'
py> 'Straße'.upper()
'STRASSE'


The right way is to casefold first, then match:

py> 'Straße'.casefold()
'strasse'


Curiously, there is an uppercase ß in old German. In recent years some 
typographers have started using it instead of SS, but it's still rare, 
and the official German rules have ß transform into SS and vice versa. 
It's in Unicode, but few fonts show it:

py> unicodedata.lookup('LATIN CAPITAL LETTER SHARP S')
'ẞ'



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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-31 Thread Chris Angelico
On Tue, Jan 1, 2013 at 2:55 PM, Steven D'Aprano
 wrote:
> On Sun, 30 Dec 2012 09:30:10 +1100, Chris Angelico wrote:
>
>> Absolutely! Though it's roughly as good to have the current cursor
>> position shown in a status line somewhere, and takes up less real
>> estate. But yes, vital to be able to see that. Even when I'm sitting
>> *right next to* my boss and communicating verbally, I'll talk about the
>> code by quoting line numbers. "Let me explain. (No, there is too much.
>> Let me sum up.) Pull up foobar dot jay ess and go to line 254-ish - see
>> how the frobnosticator always gets called with a quuxed argument?"
>
> I call shenanigans :-P
>
> I don't expect that you keep in your head the line numbers (even the line
> numbers-ish) of interesting or pertinent features of your code,
> *especially* while the code is in active development and the line numbers
> are rapidly changing. I think it is far more likely that you keep
> function, class or method names in your head (after all, you are
> presumably reading and writing those names very often), and when you want
> to demonstrate some feature, you *first* look it up by higher-level
> object ("let's see the frob_quux function") to get the line number.

Neither. You're correct that I don't memorize line numbers; but the
point of them was not to synchronize a screen with a brain, but to
synchronize two screens. So you're also correct that I look it up to
get the line number. But I'm not locating a function; if I wanted
that, I'd use that. No, I'm pointing to a specific line of code.

> Assuming that your functions and methods are not obnoxiously huge, I
> think having a good class browser which lets you jump directly to
> functions or methods is *far* more useful than line numbers, in this
> context.

They're not obnoxiously huge, but even twenty lines is too coarse when
you're trying to explain one line of code. Way too coarse. I want to
pinpoint what I'm talking about.

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


Re: Considering taking a hammer to the computer...

2012-12-31 Thread Tim Chase

On 12/31/12 19:30, worldsbiggestsabres...@gmail.com wrote:

Here is what I've learned:

[snip]

4) It's New Year's Eve and I'm trying to learn Python...?


Can't think of a much better way to spend New Year's Eve, unless 
you're learning Python while also watching fireworks. :-)


-tkc




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