[Tutor] python + sharepoint

2012-03-02 Thread Brad Hudson
Can someone assist in a very basic task of retrieving a '.txt' file
from a sharepoint document library using Python 2.4 standard
libraries? I'm certain, I need to build up some form of authentication
to pass, but do not know where to begin. Also, I do not want to
attempt to customize or install additional packages to the server for
this (Solaris).

Note: url is changed below for obvious reasons, but the traceback is untouched.

# ./get_file.py
Traceback (most recent call last):
  File ./get_file.py, line 7, in ?
result = urllib2.urlopen(url).readlines()
  File /usr/lib/python2.4/urllib2.py, line 130, in urlopen
return _opener.open(url, data)
  File /usr/lib/python2.4/urllib2.py, line 364, in open
response = meth(req, response)
  File /usr/lib/python2.4/urllib2.py, line 471, in http_response
response = self.parent.error(
  File /usr/lib/python2.4/urllib2.py, line 402, in error
return self._call_chain(*args)
  File /usr/lib/python2.4/urllib2.py, line 337, in _call_chain
result = func(*args)
  File /usr/lib/python2.4/urllib2.py, line 480, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
[root@ilhsf001h001]# cat get_file.py
#!/usr/bin/env python

import urllib2

url = 'http://myserver.com/myfile.txt'

result = urllib2.urlopen(url).readlines()

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


[Tutor] number of mismatches in a string

2012-03-02 Thread Hs Hs
Hi:
I have the following table and I am interested in calculating mismatch ratio. I 
am not completely clear how to do this and any help is deeply appreciated. 

Length     Matches
77      24A0T9T36

71      25^T9^T37

60      25^T9^T26
62      42A19



In length column I have length of the character string. 
In the second column I have the matches my reference string. 


In fist case, where 77 is length, in matches from left to right, first 24 
matched my reference string following by a extra character A, a null (does not 
account to proble) and extra T, 9 matches, extra T and 36 matches.  Totally 
there are 3 mismatches

In case 2, I lost 2 characters (^ = loss of character compared to reference 
sentence)   - 

TOMISAGOODBOY
T^MISAGOOD^OY   (here I lost 2 characters)  = I have 2 mismatches
TOMISAGOOODBOOY (here I have 2 extra characters O and O) = I have two mismatches


In case 4: I have 42 matches, extra A and 19 matches = so I have 1 mismatch


How can that mismatch number from matches string.
1. I have to count how many A or T or G or C (believe me only these 4 letters 
will appear in this, i will not see Z or B or K etc)
2. ^T or ^A or ^G or ^C will also be a mismatch


desired output:

Length     Matches   mismatches
77      24A0T9T36    3 

71      25^T9^T37     2

60      25^T9^T26     2
62      42A19             1
10      6^TTT1           3


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


Re: [Tutor] number of mismatches in a string

2012-03-02 Thread Albert-Jan Roskam
Hi,

I do not completely follow you, but perhaps you could check out this page: 
http://code.activestate.com/recipes/576869-longest-common-subsequence-problem-solver/
Another source of inspiration could be the levenshtein distance.

 
Regards,
Albert-Jan


~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a 
fresh water system, and public health, what have the Romans ever done for us?
~~ 



 From: Hs Hs ilhs...@yahoo.com
To: tutor@python.org tutor@python.org 
Sent: Friday, March 2, 2012 8:11 PM
Subject: [Tutor] number of mismatches in a string
 

Hi:
I have the following table and I am interested in calculating mismatch ratio. 
I am not completely clear how to do this and any help is deeply appreciated. 


Length     Matches
77      24A0T9T36

71      25^T9^T37

60      25^T9^T26
62      42A19





In length column I have length of the character string. 
In the second column I have the matches my reference string. 




In fist case, where 77 is length, in matches from left to right, first 24 
matched my reference string following by a extra character A, a null (does not 
account to proble) and extra T, 9 matches, extra T and 36 matches.  Totally 
there are 3 mismatches


In case 2, I lost 2 characters (^ = loss of character compared to reference 
sentence)   - 


TOMISAGOODBOY
T^MISAGOOD^OY   (here I lost 2 characters)  = I have 2 mismatches
TOMISAGOOODBOOY (here I have 2 extra characters O and O) = I have two 
mismatches




In case 4: I have 42 matches, extra A and 19 matches = so I have 1 mismatch




How can that mismatch number from matches string.
1. I have to count how many A or T or G or C (believe me only these 4 letters 
will appear in this, i will not see Z or B or K etc)
2. ^T or ^A or ^G or ^C will also be a mismatch




desired output:


Length     Matches   mismatches
77      24A0T9T36    3 

71      25^T9^T37     2

60      25^T9^T26     2
62      42A19             1
10      6^TTT1           3




thanks 
Hs.


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


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


Re: [Tutor] number of mismatches in a string

2012-03-02 Thread bob gailer

On 3/2/2012 2:11 PM, Hs Hs wrote:

Hi:
I have the following table and I am interested in calculating mismatch 
ratio. I am not completely clear how to do this and any help is deeply 
appreciated.


Length Matches
77  24A0T9T36
71  25^T9^T37
60  25^T9^T26
62  42A19


In length column I have length of the character string.
In the second column I have the matches my reference string.


In fist case, where 77 is length, in matches from left to right, first 
24 matched my reference string following by a extra character A, a 
null (does not account to proble) and extra T, 9 matches, extra T and 
36 matches.  Totally there are 3 mismatches


In case 2, I lost 2 characters (^ = loss of character compared to 
reference sentence)   -


TOMISAGOODBOY
T^MISAGOOD^OY   (here I lost 2 characters)  = I have 2 mismatches
TOMISAGOOODBOOY (here I have 2 extra characters O and O) = I have two 
mismatches



In case 4: I have 42 matches, extra A and 19 matches = so I have 1 
mismatch



How can that mismatch number from matches string.
1. I have to count how many A or T or G or C (believe me only these 4 
letters will appear in this, i will not see Z or B or K etc)

2. ^T or ^A or ^G or ^C will also be a mismatch


desired output:

Length Matches   mismatches
77  24A0T9T363
71  25^T9^T37 2
60  25^T9^T26 2
62  42A19 1
10  6^TTT1   3



I am sorry but I do not understand, and do not have the patience to wade 
through all the above in the hopes of gaining insight.


Perhaps you could restate the problem in a way that makes it crystal clear.

--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] Which computer operating system is best for Python developers?

2012-03-02 Thread Terry Carroll

(Re Python on Windows 7)

On Thu, 23 Feb 2012, Tim Golden wrote:


On 23/02/2012 09:00, Alan Gauld wrote:


If you do a reinstall, download the ActiveState version rather
than the Python.org version.


I also recommend the ActiveState distro.


I am going to third Alan's and Tim's recommendations of the Activestate 
distribution; and further suggest that you use the 32-bit version, anod 
not the 64-bit version, even if you have the 64-bit Windows 7.  Some 
Python extensions are built only for 32-bit Python and will not work with 
64-bit.


I recently ran into this on two modules; one was PIL and I cannot remember 
the other.  The easy fix was to uninstall the 64-bit Python and install 
32-bit in its place.


I'm referrng to Python 2.7 above.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] number of mismatches in a string

2012-03-02 Thread Jerry Hill
On Fri, Mar 2, 2012 at 2:11 PM, Hs Hs ilhs...@yahoo.com wrote:
 Hi:
 I have the following table and I am interested in calculating mismatch
 ratio. I am not completely clear how to do this and any help is deeply
 appreciated.

 Length     Matches
 77      24A0T9T36
 71      25^T9^T37
 60      25^T9^T26
 62      42A19


 In length column I have length of the character string.
 In the second column I have the matches my reference string.


 In fist case, where 77 is length, in matches from left to right, first 24
 matched my reference string following by a extra character A, a null (does
 not account to proble) and extra T, 9 matches, extra T and 36 matches.
  Totally there are 3 mismatches

 In case 2, I lost 2 characters (^ = loss of character compared to reference
 sentence)   -

 TOMISAGOODBOY
 T^MISAGOOD^OY   (here I lost 2 characters)  = I have 2 mismatches
 TOMISAGOOODBOOY (here I have 2 extra characters O and O) = I have two
 mismatches


 In case 4: I have 42 matches, extra A and 19 matches = so I have 1 mismatch


 How can that mismatch number from matches string.
 1. I have to count how many A or T or G or C (believe me only these 4
 letters will appear in this, i will not see Z or B or K etc)
 2. ^T or ^A or ^G or ^C will also be a mismatch


 desired output:

 Length     Matches   mismatches
 77      24A0T9T36    3
 71      25^T9^T37     2
 60      25^T9^T26     2
 62      42A19             1
 10      6^TTT1           3


It looks like all you need to do is count the number of A, T, C, and G
characters in your Matches column.  Maybe something like this:

differences = [
[77, '24A0T9T36'],
[71, '25^T9^T37'],
[60, '25^T9^T26'],
[62, '42A19']
]


for length, matches in differences:
mismatches = 0
for char in matches:
if char in ('A', 'T', 'G', 'C'):
mismatches += 1
print length, matches, mismatches


which produces the following output:
77 24A0T9T36 3
71 25^T9^T37 2
60 25^T9^T26 2
62 42A19 1

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


Re: [Tutor] python + sharepoint

2012-03-02 Thread Brad Hudson
On Fri, Mar 2, 2012 at 11:03 AM, Brad Hudson brad.hud...@gmail.com wrote:
 Can someone assist in a very basic task of retrieving a '.txt' file
 from a sharepoint document library using Python 2.4 standard
 libraries? I'm certain, I need to build up some form of authentication
 to pass, but do not know where to begin. Also, I do not want to
 attempt to customize or install additional packages to the server for
 this (Solaris).

 Note: url is changed below for obvious reasons, but the traceback is 
 untouched.

 # ./get_file.py
 Traceback (most recent call last):
  File ./get_file.py, line 7, in ?
    result = urllib2.urlopen(url).readlines()
  File /usr/lib/python2.4/urllib2.py, line 130, in urlopen
    return _opener.open(url, data)
  File /usr/lib/python2.4/urllib2.py, line 364, in open
    response = meth(req, response)
  File /usr/lib/python2.4/urllib2.py, line 471, in http_response
    response = self.parent.error(
  File /usr/lib/python2.4/urllib2.py, line 402, in error
    return self._call_chain(*args)
  File /usr/lib/python2.4/urllib2.py, line 337, in _call_chain
    result = func(*args)
  File /usr/lib/python2.4/urllib2.py, line 480, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
 urllib2.HTTPError: HTTP Error 400: Bad Request
 [root@ilhsf001h001]# cat get_file.py
 #!/usr/bin/env python

 import urllib2

 url = 'http://myserver.com/myfile.txt'

 result = urllib2.urlopen(url).readlines()

 print result
 #

Still no response on this one, but I did find a 'rather ugly' solution
using subprocess for wget to get a file from sharepoint...

#!/usr/bin/env python

import getpass
import re
import shlex
from subprocess import Popen, PIPE

# build sharepoint user/pw
# note: shlex.split requires both a raw and escaped domain string
user = r'DOMAIN\\ID'
pw = getpass.getpass('password: ')
url = 'http://myserver.com/myfile.txt'
cmd = 'wget --no-proxy --user=%s --password=%s -O- %s' % (user, pw, url)
# create the args for subprocess.Popen
args = shlex.split(cmd)
# get the tuple from the command
s = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate()
# parse the stdout part of the tuple to get the exact list I want
vms = s[0].rstrip().split('\n')
vms[:] = (re.sub('\|.*$', '', vm.rstrip()) for vm in sorted(vms))
vms[:] = (vm for vm in vms if not re.search('primary', vm))
print vms
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] number of mismatches in a string

2012-03-02 Thread Alan Gauld

On 02/03/12 19:11, Hs Hs wrote:


1. I have to count how many A or T or G or C (believe me only these 4
letters will appear in this, i will not see Z or B or K etc)


This suggests to me that its related to chromosome analysis or somesuch?

There are some python libraries for biochemistry work.
Maybe you should Google for that and see if there is something
already out there that can do what you want?

Your explanation doesn't really make sense to me outside that context 
and, since I'm not a biologist, it doesn't mean that much in that 
context either!



--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] python + sharepoint

2012-03-02 Thread Steven D'Aprano

Brad Hudson wrote:

Can someone assist in a very basic task of retrieving a '.txt' file
from a sharepoint document library using Python 2.4 standard
libraries? 


What's a sharepoint document library?

How would you retrieve a text file from it *without* using Python?

[...]

Note: url is changed below for obvious reasons, but the traceback is untouched.


Not obvious to me.


[...]

urllib2.HTTPError: HTTP Error 400: Bad Request


Does this help?

http://www.checkupdown.com/status/E400.html


My wild guess is that sharepoint (whatever that is) is expecting something in 
the url request that you're not giving; or that it doesn't like your useragent 
and/or referer and lies about the problem.




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


Re: [Tutor] python + sharepoint

2012-03-02 Thread Steven D'Aprano

Brad Hudson wrote:

Still no response on this one, but I did find a 'rather ugly' solution
using subprocess for wget to get a file from sharepoint...

#!/usr/bin/env python

import getpass
import re
import shlex
from subprocess import Popen, PIPE

# build sharepoint user/pw
# note: shlex.split requires both a raw and escaped domain string
user = r'DOMAIN\\ID'
pw = getpass.getpass('password: ')
url = 'http://myserver.com/myfile.txt'
cmd = 'wget --no-proxy --user=%s --password=%s -O- %s' % (user, pw, url)


Ah.

Well that explains why your version using urllib2 failed -- you don't give a 
username or password, and sharepoint (whatever that is!) requires one.


You might have said.

You can read the Fine Manual, which describes how to fetch Internet resources:

http://docs.python.org/howto/urllib2.html

That is written for Python 2.7, here's one for 2.4:

http://docs.python.org/dev/howto/urllib2.html


Since you need to authenticate, this will probably be helpful:

http://www.voidspace.org.uk/python/articles/authentication.shtml



--
Steven

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


[Tutor] mentorship

2012-03-02 Thread Christopher Conner

Hello folks -

I'm a little lost and seek a mentor to accelerate the learning curve  
associated with open-source development, with python in particular but not  
exclusively.


I've been an computer enthusiast / amateur programmer for 20 years. Too,  
in the past few years I've researched a variety of related topics:  
historical computer culture, modern security and cryptography, Linux  
administration and the philosophy of software development.


I also have some working knowledge of apache, website design and a compsci  
degree from 10 years ago.


NOW WHAT? HELP!

I've got some free time and I feel like I should pick an open source  
project and begin contributing, but the options are just staggering. I've  
narrowed things down to the Python language - maybe the Plone project?  
maybe helping with documentation at first? Maybe testing?


I welcome any suggestions on any point or question given.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mentorship

2012-03-02 Thread Steven D'Aprano

Christopher Conner wrote:

I've got some free time and I feel like I should pick an open source 
project and begin contributing, but the options are just staggering. 
I've narrowed things down to the Python language - maybe the Plone 
project? maybe helping with documentation at first? Maybe testing?


Think of a subject you are interested in.

Are there any useful projects related to that subject written in Python? If 
not, write one! You can put code up on PyPI or Google's code hosting:


http://code.google.com/hosting/
http://pypi.python.org/

If there are existing projects, find one that does something you are 
interested in, and try improving it:


- fix a bug
- write some tests
- add some documentation
- add some missing functionality



In other words: find an itch you have, and scratch it.



--
Steven

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


Re: [Tutor] mentorship

2012-03-02 Thread Mark Lawrence

On 03/03/2012 03:49, Christopher Conner wrote:

Hello folks -

I'm a little lost and seek a mentor to accelerate the learning curve
associated with open-source development, with python in particular but
not exclusively.

I've been an computer enthusiast / amateur programmer for 20 years. Too,
in the past few years I've researched a variety of related topics:
historical computer culture, modern security and cryptography, Linux
administration and the philosophy of software development.

I also have some working knowledge of apache, website design and a
compsci degree from 10 years ago.

NOW WHAT? HELP!

I've got some free time and I feel like I should pick an open source
project and begin contributing, but the options are just staggering.
I've narrowed things down to the Python language - maybe the Plone
project? maybe helping with documentation at first? Maybe testing?

I welcome any suggestions on any point or question given.
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



Start with http://pythonmentors.com/ ?

--
Cheers.

Mark Lawrence.

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