Re: Diagnosing socket "Connection reset by peer"

2013-05-22 Thread Matt Jones
This typically indicates that the "peer" at the other end of the tcp
connection severed the session without the typical FIN packet.  If you're
treating the printer as a "blackbox" then there really isn't anything you
can do here except catch the exception and attempt to reconnect.

*Matt Jones*


On Wed, May 22, 2013 at 3:46 AM, loial  wrote:

> I have a sockets client that is connecting to a printer and occassionally
> getting the error "104 Connection reset by peer"
>
> I have not been able to diagnose what is causing this. Is there any
> additional traceing I can do(either within my python code or on the
> network) to establish what is causing this error?
>
> Currently I am simply trapping socket.erruor
>
> Python version is 2.6
>
>
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python backup script

2013-05-06 Thread Matt Jones
Why do you have to use that file?  Why can't you copy its contents into a
new file in your working directory and make whatever changes necessary?


Example of the changes your code makes me think you want:


# The following options will be passed to all MySQL clients
[client]
#password   = your_password
port= 3306
socket  = /tmp/mysql.sock
mmz  = bleh
pass1  = blah
localhost  = bluargh


*Matt Jones*


On Mon, May 6, 2013 at 3:37 PM, MMZ  wrote:

> Thanks Matt.
> my.cnf is a readonly file and cannot be changed or modified but do you
> know of a file that stores similar information on CentOS?I think I'm not
> reading from a right file maybe.
>
> On Monday, May 6, 2013 3:46:04 PM UTC-4, Matt Jones wrote:
> > I've never used ConfigParser either, but shouldn't the "[client]"
> section have the options "mmz", "pass1", or "localhost" somewhere?  Do you
> need to add them to that file?
> >
> >
> >
> >
> > Matt Jones
> >
> >
> >
> > On Mon, May 6, 2013 at 2:20 PM, MMZ  wrote:
> >
> >
> > On Monday, May 6, 2013 3:11:33 PM UTC-4, Jerry Hill wrote:
> >
> >
> > > On Mon, May 6, 2013 at 3:01 PM, MMZ  wrote:
> >
> > >
> >
> > >
> >
> > >
> >
> > > I am trying to backup database on CentOS linux server,I'm getting
> error when running the following script. anyone can help?
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> >
> > > Traceback (most recent call last):
> >
> > >
> >
> > >   File "./backup.py", line 8, in ?
> >
> > >
> >
> > > username = config.get('client', 'mmz')
> >
> > >
> >
> > >   File "/usr/lib/python2.4/ConfigParser.py", line 511, in get
> >
> > >
> >
> > > raise NoSectionError(section)
> >
> > >
> >
> > >
> >
> > >
> >
> >
> > > I've never used ConfigParser, but that
> >
> > >
> >
> > > error message looks pretty simple to interpret.  You've set up a
> ConfigParser object, told it to read in ~/my.cnf, the asked for the value
> of section 'client', option 'mmz'.  The error indicates that your config
> files doesn't have a section named 'client'.
> >
> >
> >
> > >
> >
> > >
> >
> > >
> >
> > > What is the content of your ~/my.cnf file?
> >
> > >
> >
> > > --
> >
> > >
> >
> > >
> >
> > > Jerry
> >
> >
> >
> > Thank you for helping Jerry. Actually I found this script for debian but
> I want to use it for CentOS server so I replaced /etc/mysql/debian.cnf with
> ~/my.cnf
> >
> > the file content is:
> >
> >
> >
> >  Example MySQL config file for medium systems.
> >
> > #
> >
> > # This is for a system with little memory (32M - 64M) where MySQL plays
> >
> > # an important part, or systems up to 128M where MySQL is used together
> with
> >
> > # other programs (such as a web server)
> >
> > #
> >
> > # MySQL programs look for option files in a set of
> >
> > # locations which depend on the deployment platform.
> >
> > # You can copy this option file to one of those
> >
> > # locations. For information about these locations, see:
> >
> > # http://dev.mysql.com/doc/mysql/en/option-files.html
> >
> > #
> >
> > # In this file, you can use all long options that a program supports.
> >
> > # If you want to know which options a program supports, run the program
> >
> > # with the "--help" option.
> >
> >
> >
> > # The following options will be passed to all MySQL clients
> >
> > [client]
> >
> > #password   = your_password
> >
> > port= 3306
> >
> > socket  = /tmp/mysql.sock
> >
> >
> >
> > # Here follows entries for some specific programs
> >
> >
> >
> > # The MySQL server
> >
> > [mysqld]
> >
> > port= 3306
> >
> > socket  = /tmp/mysql.sock
> >
> > skip-locking
> >
> > key_buffer_size = 16M
> >
> > max_allowed_packet = 1M
> >
> > table_open_cache = 64
> >
> > sort_buffer_size = 512K
> >
> > net_buffer_length = 8K
> >
> > read_buffer_size = 256K
> >
> > read_rnd_buffer_size = 512K
> >
> > myisam_sort_buffer_size = 8M
> >
> >
> >
> > # Don't listen on a TCP/IP port at all. This can be a security
> enhancement,
> >
> > # if all processes that need to connect to mysqld run on the same host.
> >
> > # All interaction with mysqld must be made via Unix sockets or named
> pipes.
> >
> > # Note that using this option without enabling named pipes on Windows
> >
> > # (via the "enable-named-pipe" option) will render mysqld useless!
> >
> > #
> >
> > #skip-networking
> >
> >
> >
> > # Replication Master Server (default)
> >
> > # binary logging is required for replication
> >
> > log-bin=mysql-bin
> >
> >
> >
> > # binary logging format - mixed recommended
> >
> > binlog_format=mixed
> >
> >
> >
> > # required unique id between 1 and 2^32 - 1
> >
> > # defaults to 1 if master-host is not set
> >
> > # but will not function as a master if omitted
> >
> > server-id   = 1
> >
> > --
> >
> > http://mail.python.org/mailman/listinfo/python-list
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python backup script

2013-05-06 Thread Matt Jones
I've never used ConfigParser either, but shouldn't the "[client]" section
have the options "mmz", "pass1", or "localhost" somewhere?  Do you need to
add them to that file?

*Matt Jones*


On Mon, May 6, 2013 at 2:20 PM, MMZ  wrote:

> On Monday, May 6, 2013 3:11:33 PM UTC-4, Jerry Hill wrote:
> > On Mon, May 6, 2013 at 3:01 PM, MMZ  wrote:
> >
> >
> >
> > I am trying to backup database on CentOS linux server,I'm getting error
> when running the following script. anyone can help?
> >
> >
> >
> >
> > Traceback (most recent call last):
> >
> >   File "./backup.py", line 8, in ?
> >
> > username = config.get('client', 'mmz')
> >
> >   File "/usr/lib/python2.4/ConfigParser.py", line 511, in get
> >
> > raise NoSectionError(section)
> >
> >
> >
> > I've never used ConfigParser, but that
> >
> > error message looks pretty simple to interpret.  You've set up a
> ConfigParser object, told it to read in ~/my.cnf, the asked for the value
> of section 'client', option 'mmz'.  The error indicates that your config
> files doesn't have a section named 'client'.
> >
> >
> >
> > What is the content of your ~/my.cnf file?
> >
> > --
> >
> >
> > Jerry
>
> Thank you for helping Jerry. Actually I found this script for debian but I
> want to use it for CentOS server so I replaced /etc/mysql/debian.cnf with
> ~/my.cnf
> the file content is:
>
>  Example MySQL config file for medium systems.
> #
> # This is for a system with little memory (32M - 64M) where MySQL plays
> # an important part, or systems up to 128M where MySQL is used together
> with
> # other programs (such as a web server)
> #
> # MySQL programs look for option files in a set of
> # locations which depend on the deployment platform.
> # You can copy this option file to one of those
> # locations. For information about these locations, see:
> # http://dev.mysql.com/doc/mysql/en/option-files.html
> #
> # In this file, you can use all long options that a program supports.
> # If you want to know which options a program supports, run the program
> # with the "--help" option.
>
> # The following options will be passed to all MySQL clients
> [client]
> #password   = your_password
> port= 3306
> socket  = /tmp/mysql.sock
>
> # Here follows entries for some specific programs
>
> # The MySQL server
> [mysqld]
> port= 3306
> socket  = /tmp/mysql.sock
> skip-locking
> key_buffer_size = 16M
> max_allowed_packet = 1M
> table_open_cache = 64
> sort_buffer_size = 512K
> net_buffer_length = 8K
> read_buffer_size = 256K
> read_rnd_buffer_size = 512K
> myisam_sort_buffer_size = 8M
>
> # Don't listen on a TCP/IP port at all. This can be a security enhancement,
> # if all processes that need to connect to mysqld run on the same host.
> # All interaction with mysqld must be made via Unix sockets or named pipes.
> # Note that using this option without enabling named pipes on Windows
> # (via the "enable-named-pipe" option) will render mysqld useless!
> #
> #skip-networking
>
> # Replication Master Server (default)
> # binary logging is required for replication
> log-bin=mysql-bin
>
> # binary logging format - mixed recommended
> binlog_format=mixed
>
> # required unique id between 1 and 2^32 - 1
> # defaults to 1 if master-host is not set
> # but will not function as a master if omitted
> server-id   = 1
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie questions on Python

2013-04-16 Thread Matt Jones
When slicing: l[start:end:step]

In your example of "a[2::-1]" you are reversing the list by using a step of
-1, then you are slicing at index 2 (third element).

*Matt Jones*


On Tue, Apr 16, 2013 at 10:30 AM, Chris Angelico  wrote:

> On Wed, Apr 17, 2013 at 1:20 AM,   wrote:
> > Hi all,
> > i'm programming in python for the first time (usually i use C as
> programming language). I don't understand these results:
> >
> >>>> a=[1,2,3,4,5]
> >>>> a[:-1]
> > [1, 2, 3, 4]
> >>>> a[::-1]
> > [5, 4, 3, 2, 1]
> >>>> a[2::-1]
> > [3, 2, 1]
> >
> > what does a[2::-1] means?
>
> That's taking a slice. This page has something to say on the subject:
>
> http://docs.python.org/3.3/tutorial/introduction.html
>
> By the way, regarding your email address: there are no cheat codes in
> Python... either that, or Python *is* a cheat code. :)
>
> ChrisA
> [[ VERY HAPPY CODING ADDED ]]
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with continous incrementing of unbroken sequence for a entire working day

2013-02-28 Thread Matt Jones
Store the day as well as the serial_number in your file.  If the day is the
same as today's day, use the serial_number, if not, use 1.  At the end of
you program write the current day and serial_number.

*Matt Jones*


On Thu, Feb 28, 2013 at 1:00 PM, Morten Engvoldsen wrote:

> Hi,
> thanks for youe suggestion. I think i will go for your second option:
>
> # Runs this loop until killed
> while True
>  etc.>
>
> serial_number = salesrecord(serial_number)
>
>
> But, if i save the serial_ number value in file, then how  will it decide
> to reset the serial number to '1' when the batch  runs on next working day.
> What condition can be good, so that next day when the batch runs, it will
> know it has to reset the value 1.  Also my batch will not automatcilly run
> whole day, this is user's decision how many times he wants to run the batch
> in a day. Can you elebrate more how can i do that ...
>
> On Thu, Feb 28, 2013 at 6:43 PM, Vytas D.  wrote:
>
>> Hi,
>>
>> If you want to have one program running forever and printing
>> sales_records, you would do (one of the possibilities) something like this:
>> def salesrecord(serial_number):
>>
>> for i in salesrecord:
>>
>> print first_sales_record
>> serial_number += 1
>> print serial_number
>> return serial_number
>>
>> if __name__ == '__main__':
>> serial_number = 1
>>
>> # Runs this loop until killed
>> while True
>> > salesrecord etc.>
>>
>> serial_number = salesrecord(serial_number)
>>
>> If you want to run your script so it finishes and then saves last value
>> of serial_number, so you can pass it to your script when it runs next time,
>> you should save the value to some file and read that file on every start of
>> your program.
>>
>> Vytas
>>
>>
>> On Thu, Feb 28, 2013 at 4:31 PM, Morten Engvoldsen 
>> wrote:
>>
>>> Hi team,
>>> I need to run a batch of sales records and  the batch has serial_number
>>> filed to store the serial number of the sales record. The serial number
>>> should be set to  1 everyday when the batch runs first time in a day and
>>> the maximum serial number could be 1000.
>>>
>>> So when the batch runs first time in a day and if it has 10 records, so
>>> the last serial number will be 10. And when the batch runs 2nd time in same
>>> day, the serial number should start from 11.  In this way serial_number
>>> will increment as an unbroken series throughout the entire working day. The
>>> next day when the batch runs first time the serial number will reset to 1.
>>>
>>> Now this could be sample code how the program can count the sequence for
>>> a batch:
>>>
>>> def salesrecord():
>>> serial_number = 1
>>> for i in selesrecord:
>>> print first_sales_record
>>> serial_number += 1
>>> print serial_number
>>>
>>> salesrecord()
>>>
>>> So if the batch has 10 records and last serial number of first batch is
>>> 10, then when the batch runs second time in the same day, how the
>>> 'serial_number' will get the value of 10 and then continue the serial
>>> number for the same day,  then for next day again the serial number will
>>> start from 1.
>>>
>>> Can you let me know how can i achive this in python? As i am in learning
>>> phase of python, can you let me know what would be good approach to do this
>>> in python.
>>>
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>>
>>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: request for help

2013-02-18 Thread Matt Jones
Is this exactly how it shows in your shell?  If so, it seems you need to
indent your methods.

#
import math

def area(radius):
return math.pi * radius**2

def circumference(radius):
return 2 * math.pi * radius
#

*Matt Jones*


On Mon, Feb 18, 2013 at 1:42 PM, leonardo selmi  wrote:

> pls i need help:
>
> i have copied the following from a book and tried to make it work:
>
> import math
>
> def area(radius):
> return math.pi * radius**2
>
> def circumference(radius):
> return 2 * math.pi * radius
>
> i saved the above program from python shell into a file as "circle.py" .
> when i type "import circle" i get  error..
>
>
> kind regards
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First attempt at a Python prog (Chess)

2013-02-15 Thread Matt Jones
"Only in Python 3."

Use best practices always, not just when you have to.

*Matt Jones*


On Fri, Feb 15, 2013 at 11:52 AM, MRAB  wrote:

> On 2013-02-15 16:17, Neil Cerutti wrote:
>
>> On 2013-02-15, Oscar Benjamin  wrote:
>>
>>> if score > best_score or best_score is None:
>>>
>>
>> You need the None check first to avoid an exception from the
>> comparison.
>>
>>  Only in Python 3.
>
>
>  if best_score is None or score > best_score:
>>
>>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: Re:

2013-02-14 Thread Matt Jones
Sending back to the maillist

*Matt Jones*


-- Forwarded message --
From: 
Date: Thu, Feb 14, 2013 at 1:42 PM
Subject: Re: Re:
To: Matt Jones 


thanks for replying Matt.  I am using version 2.7.3.  im not sure  if this
is right but here is the code from
"/usr/local/lib/python2.7/dist-packages/gnuradio/gr/hier_block2.py"



# Copyright 2006,2007 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#

from gnuradio_core import hier_block2_swig
try:
import pmt
except ImportError:
from gruel import pmt

#
# This hack forces a 'has-a' relationship to look like an 'is-a' one.
#
# It allows Python classes to subclass this one, while passing through
# method calls to the C++ class shared pointer from SWIG.
#
# It also allows us to intercept method calls if needed
#
class hier_block2(object):
"""
Python wrapper around the C++ hierarchical block implementation.
Provides convenience functions and allows proper Python subclassing.
"""

def __init__(self, name, input_signature, output_signature):
"""
Create a hierarchical block with a given name and I/O signatures.
"""
self._hb = hier_block2_swig(name, input_signature, output_signature)

def __getattr__(self, name):
"""
Pass-through member requests to the C++ object.
"""
if not hasattr(self, "_hb"):
raise RuntimeError("hier_block2: invalid state--did you forget
to call gr.hier_block2.__init__ in a derived class?")
return getattr(self._hb, name)

def connect(self, *points):
"""
Connect two or more block endpoints.  An endpoint is either a
(block, port)
tuple or a block instance.  In the latter case, the port number is
assumed
to be zero.

To connect the hierarchical block external inputs or outputs to
internal block
inputs or outputs, use 'self' in the connect call.

If multiple arguments are provided, connect will attempt to wire
them in series,
interpreting the endpoints as inputs or outputs as appropriate.
"""

if len (points) < 1:
raise ValueError, ("connect requires at least one endpoint; %d
provided." % (len (points),))
else:
if len(points) == 1:
self._hb.primitive_connect(points[0].to_basic_block())
else:
for i in range (1, len (points)):
self._connect(points[i-1], points[i])

def _connect(self, src, dst):
(src_block, src_port) = self._coerce_endpoint(src)
(dst_block, dst_port) = self._coerce_endpoint(dst)
self._hb.primitive_connect(src_block.to_basic_block(), src_port,
   dst_block.to_basic_block(), dst_port)

def _coerce_endpoint(self, endp):
if hasattr(endp, 'to_basic_block'):
return (endp, 0)
else:
if hasattr(endp, "__getitem__") and len(endp) == 2:
return endp # Assume user put (block, port)
else:
raise ValueError("unable to coerce endpoint")

def disconnect(self, *points):
"""
Disconnect two endpoints in the flowgraph.

To disconnect the hierarchical block external inputs or outputs to
internal block
inputs or outputs, use 'self' in the connect call.

If more than two arguments are provided, they are disconnected
successively.
"""

if len (points) < 1:
raise ValueError, ("disconnect requires at least one endpoint;
%d provided." % (len (points),))
else:
if len (points) == 1:
self._hb.primitive_disconnect(points[0].to_basic_block())
else:
for i in range (1, len (points)):
self._disconnect(points[i-1], points[i])

def _disconnect(self, src, dst):
(src_block, src_port) = self._coerce_endpoint(src)
(dst_block, dst_port) = self._coerce_endpoint(dst)
self._hb

Re:

2013-02-14 Thread Matt Jones
Please post the code, or a link to the code...

Also, what version of python are you running this code over?

*Matt Jones*


On Thu, Feb 14, 2013 at 12:26 PM,  wrote:

>   using ubuntu 12.10 i am trying to run a python block, namely OP25, in
> GNU Radio Companion v3.6.3-35-g4435082f. i get the following error:
>
> Executing: "/home/matt/op25_grc.py"
>
> Imported legacy fsk4
> Using Volk machine: ssse3_32
> Traceback (most recent call last):
> File "/home/matt/op25_grc.py", line 493, in 
> tb = op25_grc()
> File "/home/matt/op25_grc.py", line 231, in __init__
> self.wxgui_fftsink2_0_0.set_callback(wxgui_fftsink2_0_0_callback)
> File "/usr/local/lib/python2.7/dist-packages/gnuradio/gr/hier_block2.py",
> line 54, in __getattr__
> return getattr(self._hb, name)
> AttributeError: 'gr_hier_block2_sptr' object has no attribute
> 'set_callback'
>
> i cannot find any sort of solution on the web anywhere. any sort of help
> will be much appreciated. thanks in advance.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cancel threads after timeout

2013-01-26 Thread Matt Jones
It sounds like your real problem is with your SQL query...  Is that part of
this problem under your control?  Can you break the query into smaller,
quicker, pieces that you can run in a reasonable amount of time?

If not, nesting threads might be your best programmatic solution.  Heed
Jason's warning though that the SQL Server my still be working even if you
cancel an operation from the outside (which could compound your problem).

*Matt Jones*


On Sat, Jan 26, 2013 at 9:43 AM, Jason Friedman  wrote:

> > Sometimes it happens that a query on one of the database servers
> > takes longer than expected and impedes the generation of this report
> > (that's right, the queries are ran sequential). What I am trying to
> > achieve is to parallelize the queries on each database server and to be
> > able to cancel one of them if it takes longer than X minutes.
>
> Only answering a small portion of your question 
> Assuming you are able to figure out how to "cancel" a thread or
> process on your side, it is possible the database itself will not
> respect that.  In other words, if you execute "SELECT ..." singly,
> outside of Python, and type CNTL-C, does your database quickly
> recognize you are no longer interested in the result set and stop its
> work?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Slightly OT: What metro areas are best for a software development career?

2013-01-21 Thread Matt Jones
Check out this article.  It lists some information about IT/Sofware jobs
and places where you can get them.  I recommend Austin personally, as I've
lived for a number of years.

http://msn.careerbuilder.com/Article/MSN-3218-Job-Info-and-Trends-A-closer-look-at-the-fast-growing-technology-field/?SiteId=cbmsn43218&sc_extcmp=JS_3218_advice

*Matt Jones*


On Mon, Jan 21, 2013 at 10:18 AM, Jason Hsu  wrote:

> I am looking for a position as a software development engineer.  I'm
> currently learning to develop Android apps (
> http://www.jasonhsu.com/android-apps), and I use Python for implementing
> Doppler Value Investing (http://www.dopplervalueinvesting.com) and for
> developing Swift Linux (http://www.swiftlinux.org).  NOTE: Thanks to
> those of you who answered the questions I asked as I developed Doppler
> Value Investing.
>
> I currently live in Minnesota about 50 miles west of Minneapolis, and I am
> considering moving.  What are the best metro areas (Silicon Valley, Los
> Angeles, San Diego, Chicago, Twin Cities, Boston, NYC, DC, etc.) for a
> software development career, how would you rank them, and why?
>
> The Twin Cities metro area has a technical community portal called
> http://tech.mn .  Are there analogous technical community portals for
> other metro areas?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inconsistent behaviour of methods waiting for child process

2013-01-18 Thread Matt Jones
What version of python and os are you running?

*Matt Jones*


On Fri, Jan 18, 2013 at 6:04 AM, Marcin Szewczyk wrote:

> Hi,
>
> I've done some experiments with:
> 1) multiprocessing.Process.join()
> 2) os.waitpid()
> 3) subprocess.Popen.wait()
>
> These three methods behave completely different when interrupted with a
> signal which I find disturbing.
>
> Reactions are:
> 1) exit with no exception or special return code
> 2) OSError exception
> 3) quiet retry (no exit)
>
> The 1) case is very impractical.
>
> Is there any movement towards standardization of those 3?
>
> Am I missing something and there is a way to get more information from
> Process.join()?
>
> --
> Marcin Szewczyk   http://wodny.org
> mailto:marcin.szewc...@wodny.borg  <- remove b / usuĊ„ b
> xmpp:wo...@ubuntu.pl  xmpp:wo...@jabster.pl
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using inner dict as class interface

2013-01-16 Thread Matt Jones
Or do what Steven said if its exactly a dict and doesn't require special
management of the underlying dict.

*Matt Jones*


On Wed, Jan 16, 2013 at 8:58 AM, Matt Jones wrote:

> Explicit is better than implicit.  Define the dunder methods so you know
> exactly what your class is doing when being indexed.  You only need
> __getitem__ and __setitem__ really, but if you want to treat it just like a
> dict you'll need __delitem__, __len__, __iter__, __contains__ as well.
>
> *Matt Jones*
>
>
> On Wed, Jan 16, 2013 at 8:42 AM, Florian Lindner wrote:
>
>> Hello,
>>
>> I have a:
>>
>> class C:
>>def __init__(self):
>>   d = dict_like_object_created_somewhere_else()
>>
>>   def some_other_methods(self):
>> pass
>>
>>
>> class C should behave like a it was the dict d. So I could do:
>>
>> c = C()
>> print c["key"]
>> print len(c)
>>
>> but also
>>
>> c.some_other_method()
>>
>> How can I achieve that? Do I need to define all methods like
>> __getitem__, __len__, ... (what else?) to access the inner dict or is
>> there something more slick?
>>
>> Thanks,
>>
>> Florian
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using inner dict as class interface

2013-01-16 Thread Matt Jones
Explicit is better than implicit.  Define the dunder methods so you know
exactly what your class is doing when being indexed.  You only need
__getitem__ and __setitem__ really, but if you want to treat it just like a
dict you'll need __delitem__, __len__, __iter__, __contains__ as well.

*Matt Jones*


On Wed, Jan 16, 2013 at 8:42 AM, Florian Lindner wrote:

> Hello,
>
> I have a:
>
> class C:
>def __init__(self):
>   d = dict_like_object_created_somewhere_else()
>
>   def some_other_methods(self):
> pass
>
>
> class C should behave like a it was the dict d. So I could do:
>
> c = C()
> print c["key"]
> print len(c)
>
> but also
>
> c.some_other_method()
>
> How can I achieve that? Do I need to define all methods like
> __getitem__, __len__, ... (what else?) to access the inner dict or is
> there something more slick?
>
> Thanks,
>
> Florian
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help

2013-01-11 Thread Matt Jones
Pay isn't linked to the "people" in any way.  A dictionary would serve this
purpose better (at least in this simple example).

database = {
'Mac' : 1000,
'Sam' : 2000
}

name = raw_input('Enter your name:')
if name in database.keys(): print "your pay is $", database[name]

*Matt Jones*


On Thu, Jan 10, 2013 at 12:35 PM,  wrote:

>   pls this is a code to show the pay of two people.bt I want each of to
> be able to get a different money when they enter their user name,and to use
> it for about six people.
> database = [
> ['Mac'],
> ['Sam'],
> ]
> pay1 = 1000
> pay2 = 2000
>
> name = raw_input('Enter your name: ')
> if [name] in database:print "your pay is $",pay
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class confusion

2013-01-09 Thread Matt Jones
Does this look sufficient for what?  You haven't actually told us what it
is you're trying to accomplish.  I gave you the "how", you must supply the
"why".

*Matt Jones*


On Wed, Jan 9, 2013 at 6:43 PM, Rodrick Brown wrote:

> Can anyone care to advise on the following? Based on the responses does
> this look sufficient?
>
> #!/opt/local/bin/python
>
> class SystemList(object):
> sysmap = { '1039' : 'nebula',
>'1040' : 'mercury'}
>
> def __init__(self, sysid):
> self.sysid = sysid
>
> def get_sysname(self):
> return self.sysmap[self.sysid]
>
> class System(object):
> def __init__(self):
> pass
>
> def get_hostname(self,sysid):
> return  SystemList(sysid)
>
> if __name__ == '__main__':
> sc = System()
>
> for sysid in ('1039','1040'):
> print(sc.get_hostname(sysid).get_sysname())
>
>
>
> On Wed, Jan 9, 2013 at 5:18 PM, Rodrick Brown wrote:
>
>> On Wed, Jan 9, 2013 at 4:34 PM, Matt Jones 
>> wrote:
>>
>>> # Something like...
>>>
>>> class SystemList(object):
>>>def get_systemid(self):
>>>   return "System Id: bleh"
>>>
>>>def get_running_kernel(self):
>>>   return "Kernel: bleh"
>>>
>>>
>>> class SatelliteConnect(object):
>>>def get_systemlist(self):
>>>   return SystemList()
>>>
>>>
>>> # Now the code you wrote would work, only return those literals thought,
>>> you'd want to do something meaningful inside of SystemList's methods.
>>>
>>>
>> Thanks for the tip Matt, I had no idea it was so simple. :-)
>>
>>
>>>  *Matt Jones*
>>>
>>>
>>> On Wed, Jan 9, 2013 at 3:28 PM, MRAB  wrote:
>>>
>>>> On 2013-01-09 20:13, Rodrick Brown wrote:
>>>>
>>>>> How can I make a class that has methods with attributes and other
>>>>> functions?
>>>>> I see a lot of code
>>>>>
>>>>>
>>>>> I'm reading the documentation to Redhat's Satellite software which has
>>>>> a
>>>>> XMLRPC interface and wrote the following code to test the api.
>>>>>
>>>>> I would like to extend this code to support methods with methods? I see
>>>>> this done a lot in python code but I'm not sure how to accomplish
>>>>> something like this?
>>>>>
>>>>> i.e.
>>>>>
>>>>> sc = SatelliteConnect()
>>>>> sc.get_systemlist().get_**systemid() ?
>>>>> or
>>>>> sc.get_systemlist().get_**running_kernel()
>>>>>
>>>>> How does one chain methods and attributes like this with classes?
>>>>>
>>>>>  [snip]
>>>> This:
>>>>
>>>> sc.get_systemlist().get_**systemid()
>>>>
>>>> simply means that the method "get_systemlist" returns an instance of
>>>> some class (let's call it "SystemList") which has a method
>>>> "get_systemid".
>>>>
>>>> --
>>>> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>>>>
>>>
>>>
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>>
>>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class confusion

2013-01-09 Thread Matt Jones
# Something like...

class SystemList(object):
   def get_systemid(self):
  return "System Id: bleh"

   def get_running_kernel(self):
  return "Kernel: bleh"


class SatelliteConnect(object):
   def get_systemlist(self):
  return SystemList()


# Now the code you wrote would work, only return those literals thought,
you'd want to do something meaningful inside of SystemList's methods.

*Matt Jones*


On Wed, Jan 9, 2013 at 3:28 PM, MRAB  wrote:

> On 2013-01-09 20:13, Rodrick Brown wrote:
>
>> How can I make a class that has methods with attributes and other
>> functions?
>> I see a lot of code
>>
>>
>> I'm reading the documentation to Redhat's Satellite software which has a
>> XMLRPC interface and wrote the following code to test the api.
>>
>> I would like to extend this code to support methods with methods? I see
>> this done a lot in python code but I'm not sure how to accomplish
>> something like this?
>>
>> i.e.
>>
>> sc = SatelliteConnect()
>> sc.get_systemlist().get_**systemid() ?
>> or
>> sc.get_systemlist().get_**running_kernel()
>>
>> How does one chain methods and attributes like this with classes?
>>
>>  [snip]
> This:
>
> sc.get_systemlist().get_**systemid()
>
> simply means that the method "get_systemlist" returns an instance of
> some class (let's call it "SystemList") which has a method
> "get_systemid".
>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question on for loop

2013-01-03 Thread Matt Jones
Yeah, this seems like a bad idea.  What exactly are you trying to do here?

Maybe using a dictionary is what you want?


d = {
'first' : 'banana',
'second' : 'apple',
'third'  : 'mango'
}

for key, value in d.items():
print key, value


However I'm still not sure why you'd want to do this.

*Matt Jones*


On Thu, Jan 3, 2013 at 2:21 PM, MRAB  wrote:

> On 2013-01-03 20:04, subhabangal...@gmail.com wrote:
>
>> Dear Group,
>> If I take a list like the following:
>>
>> fruits = ['banana', 'apple',  'mango']
>> for fruit in fruits:
>> print 'Current fruit :', fruit
>>
>> Now,
>> if I want variables like var1,var2,var3 be assigned to them, we may take,
>> var1=banana,
>> var2=apple,
>> var3=mango
>>
>> but can we do something to assign the variables dynamically I was thinking
>> of
>> var_series=['var1','var2','**var3']
>> for var in var_series:
>>for fruit in fruits:
>> print var,fruits
>>
>> If any one can kindly suggest.
>>
>> Regards,
>> Subhabrata
>>
>> NB: Apology for some alignment mistakes,etc.
>>
>>  Why would you want to do that? Creating names dynamically like that is
> a bad idea. Just keep them in a list, like they are already.
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: building python from source

2013-01-03 Thread Matt Jones
Run the unittests.  the "test___all___.py" test runner can be found under
your python installation directory's lib/python-X.X/test/.


*Matt Jones*


On Thu, Jan 3, 2013 at 8:43 AM, Rita  wrote:

> For those building python from source what are some tests you do to make
> sure the compilation and installation is up to standard. For instance here
> are some thing I do:
> Tk functionality
> sqlite module
> Python is compiled with shared object (important for wsgi)
> Proper preloading of python libraries (set the proper -rpath flag for gcc)
>
> Any others?  The people who manage distributions what do they check with
> for regression tests?
>
>
>
>
>
> --
> --- Get your facts first, then you can distort them as you please.--
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2013-01-01 Thread Matt Jones
rooms_on_floor is being set by the manual input for each floor iterated
over in your for loop.  My guess is your total_rooms value equals the rooms
from the last floor you processed.  Same goes for the occupied_rooms.
 You'll want a separate variable to increment after each occupied_rooms or
rooms_on_floor is received from the user.

something like...:

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

*Matt Jones*


On Tue, Jan 1, 2013 at 2:14 PM,  wrote:

> OK, thank you all for your help yesterday!
>
> Here's where we are today (using python 3.3.0)
>
> He has everything running well except for the final calculations - he
> needs to be able to total the number of rooms in the hotel, as well as the
> number of occupied rooms.  We have tried several different things and can't
> come up with a successful command.  Any help you can give will be much
> appreciated!!
>
> Here's what he's got:
>
> #This program will calculate the occupancy rate of a hotel
> floor_number = 0
> rooms_on_floor = 0
> occupied_rooms = 0
> total_rooms = 0
> total_occupied = 0
>
>
>
> number_of_floors = int(input("How many floors are in the hotel?: "))
> while number_of_floors < 1:
> print ("Invalid input! Number must be 1 or more")
> number_of_floors = int(input("Enter the number of floors in the hotel:
> "))
>
> for i in range(number_of_floors):
> 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! Number must be 10 or more")
> 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)
>
> #CALCULATE OCCUPANCY RATE FOR HOTEL
> print()
> total_rooms = sum(rooms_on_floor) #DOESN'T WORK!
> total_occupied = sum(occupied_rooms) #DOESN'T WORK!
> hotel_occupancy = total_occupied / total_rooms
> vacant_rooms = total_rooms - total_occupied
> 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)
> print ("The number of vacant rooms at this hotel is ",vacant_rooms)
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Developer Job Opportunities

2012-03-02 Thread Matt Jones
I have an opportunity for talented Python Developers with Django experience 
based in the South of the UK.

I am recruiting for a funded new venture set up by two successful entrepreneurs 
who are experienced and well--respected scientists and mathematicians. They're 
building a new and radical way of learning Maths; an advanced technological 
platform (iPad / Cloud based) with unique data gathering and analysis 
capabilities the program will create a world beating, cutting edge product.

They are on the hunt for Python developers to build the interface of a brand 
new cloud hosted web app that will be rolled out on iPad as well as a bespoke 
CMS, web portal and internal visualization platform.

The team  are working in brand new, expansive offices (45,000 square feet, free 
lunch, onsite gym, games room, poker room with casino grade tables, 5-A-Side 
football pitch).

This is an exciting opportunity to become a core member of the development team 
in a growing company that will be providing a technical challenge in a 
fantastic working environment all in aid of a good cause.

If you would like to discuss the role in more detail please contact me at 
matt.jo...@radiusrecruitment.co.uk I 
can also provide photos of the office, details on working environment etc.
-- 
http://mail.python.org/mailman/listinfo/python-list