Re: [Tutor] recursivity and lists

2016-03-05 Thread Robert Nanney
Would this meet the requirements?

merged_list = list1.extend(list2).sort()
On Mar 4, 2016 3:34 PM, "Danny Yoo"  wrote:

> > As we can see, we have to do a lot more consideration of what state
> > our values are in, due to all the mutation happening.  It also shows
> > that the second recursive call to the linear_merge() is not really
> > using it to merge: it's really trying to select the list that was used
> > to accumulate results.  We'd get the same results with:
> >
> > ##
> > def linear_merge1(list1, list2):
> >   if list1==[]: return list2
> >   elif list2==[]: return list1
> >   elif list1[-1]>list2[-1]:
> > a=list1.pop()
> > linear_merge(list1,list2).append(a)
> > return list1 or list2
> >   else:
> > a=list2.pop()
> > linear_merge(list1,list2).append(a)
> > return list1 or list2
> > ##
>
>
> Sorry: I made a mistake when typing out the internal recursive calls.
> Substitute 'linear_merge1' in places where it had 'linear_merge'.
>
> #
> def linear_merge1(list1, list2):
>   if list1==[]: return list2
>   elif list2==[]: return list1
>   elif list1[-1]>list2[-1]:
> a=list1.pop()
> linear_merge1(list1,list2).append(a)
> return list1 or list2
>   else:
> a=list2.pop()
> linear_merge1(list1,list2).append(a)
> return list1 or list2
> ##
>
>
>
> > So, yeah, the code is *much* too clever for it's own good.  :P
>
> Substitute "it's" with "its".
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] responding to command line

2015-11-25 Thread Robert Nanney
I like to use paramiko for these types of things. Of course I don't have
all the details but from the info you have provided it seems like you
should be able to do this with ansible itself.

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


Re: [Tutor] Bitwise

2015-10-14 Thread Robert Nanney
To elaborate a little more this is comparing the 'one' bit. Any odd number
will have the 'one' bit set.
On Oct 14, 2015 6:30 PM, "Joel Goldstick"  wrote:

> On Wed, Oct 14, 2015 at 4:47 PM, ਨਿਹੰਗ ਪੰਜਾਬੀ  wrote:
>
> >  'if (n & 1)'  below works but I don't understand why/how.  Kindly help.
> >
> > ==
> > >>> def fn(n):
> > ... if (n & 1):
> > ... print "n is odd"
> > ... else:
> > ... print "n is even"
> > ...
> > >>> fn(5)
> > n is odd
> > >>> fn(4)
> > n is even
> >
> > ===
> >
>
> & is a bitwise operator, so any odd number and 1 will be one (true), and
> any even number will be zero (false)
> Any
>
> >
> > Thanks
> > Ni
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
> >
>
>
>
> --
> Joel Goldstick
> http://joelgoldstick.com/stats/birthdays
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ftp socket.error

2015-09-11 Thread Robert Nanney
I may be mistaken, but it looks like you are trying to open the socket on
port 2021. Standard ftp uses 21. Is the server listening on 2021?
On Sep 11, 2015 5:29 PM, "Martin A. Brown"  wrote:

>
> Hi there Richard,
>
> Strictly speaking, it's no Python question, but... good ol' FTP.
>
> socket.error: [Errno 113] No route to host

>>>
> Your program is receiving an EHOSTUNREACH.
>
>   >>> import errno
>   >>> errno.errorcode[113]
>   'EHOSTUNREACH'
>
> This occurs at precisely the moment that your program is trying to
> initiate a data transfer.  Every firewall administrator in the world loves
> FTP for precisely this reason.  (And, when I say "love", you can replace
> this with a verb or  of your choice.)
>
> Without packet captures, I will merely guess (based on experience).
>
>   1. The receiving machine is running the Python program, builds a
>  connection on port 21 (this is called the FTP command
>  channel), you log in and all is well.
>   2. The moment you try to transfer any data, the FTP client (your
>  receiving machine) and the FTP server negotiate either FTP
>  passive mode or FTP active (retronym) mode.  I'm guessing
>  that your FTP client is choosing passive mode.  (Your FTP
>  client might produce logging of this negotiation.)
>   3. Using the connection information, the client attempts to build
>  an FTP data channel.  So, your machine running the Python
>  program initiates a connection to the FTP server.
>   4. The FTP server is (probably) configured to allow connections
>  inbound to TCP/21 (FTP Command Channel), but doesn't know to
>  allow the connections to the ephemeral port(s) negotiated
>  during step 2 (above).  So, the firewall on the FTP Server
>  sends an ICMP Type 3, Code 1 [0].
>
> Figured it out. On the receiving machine  I had to
>>>
>>> # modprobe ip_conntrack_ftp
>>>
>>
> Right instinct!  Try this same command on the FTP server side. Unless your
> Python FTP client is negotiating active mode, the server will be the
> "problem" in this case.
>
> No, apparently I didn't figure it out. I thought I had as after the
>> modprobe I was getting a an EOFError, but now I'm getting the no route to
>> host error again. I can ping it, and as you can see from the original post,
>> I am able to establish a connection and log in, it's just when I try to
>> send a file it goes bollocks up. Still need ideas.
>>
>
> Hopefully, my idea #1 helps.  (If not, you'll need to do some packet
> captures and probably crank up the logging on the FTP server, too.)
>
> I do have another idea, though.  Have you ever wondered about the slow
> demise of FTP?  All of this command-channel, data-channel, PORT or PASV
> nonsense goes away when you use a protocol that runs over a single TCP
> port.  Worked fine in the early days of the Internet before firewalls and
> NAT.
>
> Anyway, short idea #2:
>
>   If it's anonymous access, use HTTP.
>   If authenticated access, use ssh/scp/sftp.
>
> Good luck,
>
> -Martin
>
>  [0] http://www.networksorcery.com/enp/protocol/icmp/msg3.htm
>
> --
> Martin A. Brown
> http://linux-ip.net/
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Unpacking lists

2014-07-08 Thread Robert Nanney
Hello All,

I have the following code.  The idea is to have one list that contains
all of the items from the different iterable types and maintain the
order of the items.

Python 2.7.6 |Anaconda 2.0.0 (x86_64)| (default, May 27 2014, 14:58:54)

#!/usr/bin/python
#list_test2.py

list1 = [1, 8, 15]
list2 = [2, 9, 16]
list3 = [[3, 4, 5, 6], [10, 11, 12, 13], [17, 18, 19, 20]]
list4 = [7, 14, 21]
one_list = zip(list1, list2, list3, list4)
print Start: {}.format(one_list)
first_round = [one_list[x][y] for x in range(len(list3)) for y in range(4)]
print First Round: {}.format(first_round)
second_round = []
for i in first_round:
if not isinstance(i, list):
second_round.append(i)
else:
for x in range(len(i)):
second_round.append(i[x])
print Second round: {}.format(second_round)

While this seems to do the trick, I feel there is probably a
better/more pythonic way to accomplish the same thing.

One thing to keep in mind is that the number of items in each list
will always be the same, ie... if list1, list2, list4 have 4 items
each, there will be 4 lists in list3.

Any advice would be greatly appreciated!

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