jarod_v6@libero.it | 22 Jul 13:10 2014
Picon

How to show dictionary item non present on file

Hin there!!!

I have a niave question on dictionary analysis: 
If you have a dictionary like this:
diz
Out[8]: {'elenour': 1, 'frank': 1, 'jack': 1, 'ralph': 1}

and you have a list and you want to know which  keys are not present on my 
dictionary the code are simple.
for i in diz.keys():
   ...:     if i in mitico:
   ...:         print "NO"
   ...:     else:
   ...:         print i
   ...:         
NO

But I havethis problem I have a file and I want to know which elements are not 
present on my file from dictionary.
 more data.tmp 
jack	1
pippo	1
luis	1
frate	1
livio	1
frank	1

with open("data.tmp") as p:
    for i in p:
        lines= i.strip("\n").split("\t")
(Continue reading)

yarteydegreat2@gmail.com | 21 Jul 08:57 2014
Picon

Unhandled exception

I just want to know if an unhandled exception is a bug in my programs!

Degreat

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
keith papa | 20 Jul 22:57 2014

Is this possible for a newbie?

Am a newbie to programming and I started learning python days ago. I have this idea I want to execute, am a big sport and fantasy fan and I wanted to create something that will make it things a little easy for me. My idea is simple I want to create a program that I can enter name and some information about a player, for example: 


NFL plays:


Jamaal Charles RB : ATT 259 , YDS 1,287 , AVG 5.0, TD 12, REC 70


Tony Romo QB: CMP% 63.9, YDS 3,828 , TD 31, INT 10, Rating 96.7


Dez Bryant WR: REC 93, YDS 1,233, AVG 13.3, LNG 79, TD 13


and other players information.


I want to be able to ask the program which QB is best on my list and it give me the names of all the QB on my list, or ask for WR on my list and it gives me all the WR on my list, and also I want to be able to crossed out name simply by typing the players name.

What do I need to lean in order to accomplish this? string, variable functions?

feel free to ask any questions.
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
LN A-go-go | 20 Jul 17:40 2014

(no subject)

My apologies Python Gurus for repeating this request for read, write, split and append from a text file in notepad.  I worked on it till late last night and will again today.  I can't seem to get past trying to write the names to one list and the numbers (converted to integers) to the other.  My lists come up empty.

I am a full-time firefighter that taught myself to use ArcGIS to make maps and now am in school so I can move into emergency mgmt.  I can't seem to teach myself Python and I am really trying.
thank-you,

LN


>>> filename = "C:/Python27/egund919/Program1/BOJ.txt"
>>> myfile = open(filename,"r")
>>> newfile = "C:/Python27/egund919/Program1/BOJ_B.txt"
>>> mynewfile = open(newfile,"w")
>>> while True:
 line = myfile.readline()
 print line
 mynewfile.write(line)
 if not line: break
 
States OJ
AK 36
AL 39
AR 39
AZ 45
CA 61
CO 54
CT 61
DC 93
DE 62
FL 51
GA 47
HI 72
IA 54
ID 36
IL 62
IN 50
KS 41
KY 41
LA 40
MA 62
MD 62
ME 58
MI 57
MN 54
MO 49
MS 43
MT 47
NC 50
ND 45
NE 41
NH 54
NJ 57
NM 57
NV 55
NY 62
OH 51
OK 34
OR 57
PA 55
RI 63
SC 45
SD 45
TN 42
TX 44 div>
UT 34
VA 53
VT 67
WA 58
WI 56
WV 43
WY 33

>>> myfile.close()
>>> infile = open('C:/Python27/egund919/Program1/BOJ_B.txt','r')
>>> import string
>>> state_name = []
>>> data_value = []
>>> counter = 0
>>> x = 0
>>> line = infile.readline()
>>> while True:
              line = infile.readline()
              if not line: break
              counter = counter + 1
              States, OJ = string.split(line)
              XSTATES = str(States)
              XNUM = int(OJ)
              state_name.append(XSTATES)
              data_value.append(XNUM)
 
>>> len(counter)
Traceback (most recent call last):
  File "<pyshell#29>", line 1, in <module>
    len(counter)
TypeError: object of type 'int' has no len()
>>> counter.count
Traceback (most recent call last):
  File "<pyshell#30>", line 1, in <module>
    counter.count
AttributeError: 'int' object has no attribute 'count'
>>> len(state_name)
0
>>> list.state_name
Traceback (most recent call last):
  File "<pyshell#32>", line 1, in <module>
    list.state_name
AttributeError: type object 'list' has no attribute 'state_name'


_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
LN A-go-go | 19 Jul 23:27 2014

Read, Write, Split and Append lines from a text file

            
I have given it all I got: a week trying to open, read, write, split, append, convert to integers and then manipulate the data.  I have attached the file I want to pull the names and numbers from.  I'll cut and paste it incase that doesn't work and then include a sample of the python shell code. 

AK 36
AL 39
AR 39
AZ 45
CA 61
CO 54
CT 61
DC 93
DE 62
FL 51
GA 47
HI 72
IA 54
ID 36
IL 62
IN 50
KS 41
KY 41
LA 40
MA 62
MD 62
ME 58
MI 57
MN 54
MO 49
MS 43
MT 47
NC 50
ND 45
NE 41
NH 54
NJ 57
NM 57
NV 55
NY 62
OH 51
OK 34
OR 57
PA 55
RI 63
SC 45
SD 45
TN 42
TX 44
UT 34
VA 53
VT 67
WA 58
WI 56
WV 43
WY 33

# and now my newbie attempt:
# I can get this far in approach #1
>>> filename = "z:/Geog482/egund919/Program1/BOJ.txt"
>>> myfile = open(filename,"r")
>>> newfile = "z:/Geog482/egund919/Program1/BOJ_B.txt"
>>> mynewfile = open(newfile,"w")
>>> while True:
 line = myfile.readline()
 print line
 mynewfile.write(line)
 if not line: break
 
States OJ
AK 36
AL 39
AR 39
AZ 45
CA 61
CO 54
CT 61
DC 93
DE 62
FL 51
GA 47
HI 72
IA 54
ID 36
IL 62
IN 50
KS 41
KY 41
LA 40
MA 62
MD 62
ME 58
MI 57
MN 54
MO 49
MS 43
MT 47
NC 50
ND 45
NE 41
NH 54
NJ 57
NM 57
NV 55
NY 62
OH 51
OK 34
OR 57
PA 55
RI 63
SC 45
SD 45
TN 42
TX 44
UT 34
VA 53
VT 67
WA 58
WI 56
WV 43
WY 33


In approach number 2: trying to append, convert to integer, but the list comes up empty:

>>> infile = open('C:/Python27/egund919/Program1/BOJ_B.txt','r')
>>> import string
>>> state_name = []
>>> data_value = []
>>> counter = 0
>>> x = 0
>>> line = infile.readline()
>>> while True:
              line = infile.readline()
              if not line: break
              counter = counter + 1
              States, OJ = string.split(line)
              XSTATES = str(States)
              XNUM = int(OJ)
              state_name.append(XSTATES)
              data_value.append(XNUM)
 
>>> type(data_value)
<type 'list'>
>>> print(data_value)
[]
>>> print (line)

All I get is errors from here on out.....


LN
States	OJ
AK	36
AL	39
AR	39
AZ	45
CA	61
CO	54
CT	61
DC	93
DE	62
FL	51
GA	47
HI	72
IA	54
ID	36
IL	62
IN	50
KS	41
KY	41
LA	40
MA	62
MD	62
ME	58
MI	57
MN	54
MO	49
MS	43
MT	47
NC	50
ND	45
NE	41
NH	54
NJ	57
NM	57
NV	55
NY	62
OH	51
OK	34
OR	57
PA	55
RI	63
SC	45
SD	45
TN	42
TX	44
UT	34
VA	53
VT	67
WA	58
WI	56
WV	43
WY	33
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Chris | 18 Jul 05:54 2014
Picon

Using module Facebook

Dear All,

I'm trying to use the facebook-sdk for python [1]. I'm asking here and
not on the SDK groups, because I think this is a basic beginner's
question, not directly related to the framework.

I installed facebook-sdk:
	virtualenv .
	source bin/activate
	pip install facebook-sdk
	pip install requests

and I'm trying to use it now:

	#!/usr/bin/python
	from facebook import Facebook
	token = 'xxx'
	graph = facebook.GraphAPI(token)
	profile = graph.get_object("me")
	friends = graph.get_connections("me", "friends")
	friend_list = [friend['name'] for friend in friends['data']]
	print friend_list

but I'm getting the following error:

	(facebook)[chris <at> cd facebook]$ ./fb1.py
	Traceback (most recent call last):
	  File "./fb1.py", line 3, in <module>
	    from facebook import Facebook
	ImportError: No module named facebook

facebook.py is in:

	./lib/python2.6/site-packages/facebook.py

Thank you in advance.

[1] https://github.com/pythonforfacebook/facebook-sdk

--

-- 
Christian
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Santosh Kumar | 17 Jul 20:35 2014
Picon

Modules to work with curl.

Hi,

I am currently working on a project , which has lots of curl commands. I am using subprocess.Popen to run these curl commands. But somehow i see its bit slow.
Is there a way/module by which i can improve the performance of the program.

Thanks,
--
D. Santosh Kumar
RHCE | SCSA
+91-9703206361


Every task has a unpleasant side .. But you must focus on the end result you are producing.

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Jose Amoreira | 17 Jul 19:26 2014
Picon

Surprising behaviour of optional argument

Hello
I stumbled on something I found surprising. I'm using standard python 
(cpython, I guess) 2.7 on openSuse 13.1.

Consider the function

In [2]: def f(x,y=[]):
    ...:     print y
    ...:     y.append(x)
    ...:     return x

This is the output of repeated calls to this function:

In [3]: f(1)
[]
Out[3]: 1
In [4]: f(2)
[1]
Out[4]: 2
In [5]: f(3)
[1, 2]
Out[5]: 3

So, the function seems to keep the value of the optional argument y over 
repeated calls. I was expecting that the optional argument, if not set 
explicitly in the calling command, would always assume the default value 
(the empty list), at every call.

I guess it has something to do with the mutability of the optional 
argument (in this case, a list), because it works as I expect if the 
optional argument is an int, for instance:

In [8]: def g(x,y=0):
    ...:     print y
    ...:     y += x
    ...:     return x
    ...:

In [9]: g(1)
0
Out[9]: 1
In [10]: g(2)
0
Out[10]: 2

(No memory of previous calls to the function.)
Is there a rationale for this behavior?
Thanks for any help,
Ze
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Mitesh H. Budhabhatti | 17 Jul 06:25 2014
Picon

Python open source for beginners

I am learning Python 3 for fun and as hobby.  I am experienced in C#, ASP.Net.  I want to gain more knowledge in Python.  Can somebody please suggest open source projects/sites?
Thanks

Warm Regards,
Mitesh H. Budhabhatti
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Jose Amoreira | 16 Jul 13:49 2014
Picon

Question about style

Hello
I wrote a function that, given a list of numbers, finds clusters of 
values by proximity and returns a reduced list containing the centers of 
these clusters. However, I find it rather unclear. I would appreciate 
any comments on how pythonic my function is and suggestions to improve 
its readability.
The function is:

def aglomerate(x_lst, delta=1.e-5):
     clusters = [] #list of pairs [center, number of clustered values]
     for x in x_lst:
         close_to = [abs(x - y) < delta for y,_ in clusters]
         if any(close_to):
             # x is close to a cluster
             index = close_to.index(True)
             center, n = clusters[index]
             #update the cluster center including the new value,
             #and increment dimension of cluster
             clusters[index] = (n * center + x)/(n+1), n+1
         else:
             # x does not belong to any cluster, create a new one
             clusters.append([x,1])
     # return list with centers
     return [center for center, _ in clusters]

Examples:
1. No clusters in x_lst:
In [52]: aglomerate([1., 2., 3., 4.])
Out[52]: [1.0, 2.0, 3.0, 4.0]

2. Some elements in x_lst are equal:
In [53]: aglomerate([1., 2., 1., 3.])
Out[53]: [1.0, 2.0, 3.0]

3. Some elements in x_lst should be clustered:
In [54]: aglomerate([1., 2., 1.1, 3.], delta=0.2)
Out[54]: [1.05, 2.0, 3.0]

So, the function seems to work as it should, but can it be made more 
readable?

Thanks for any help.
Ze
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

jarod_v6@libero.it | 16 Jul 10:04 2014
Picon

R: Tutor Digest, Vol 125, Issue 49

Hi there!!!
I have a file  with this data
['uc002uvo.3 ', 'uc001mae.1']
['uc010dya.2 ', 'uc001kko.2']
['uc003ejx.2 ', 'uc010yfr.1']
['uc001bhk.2 ', 'uc003eib.2']
['uc001znc.2 ', 'uc001efn.2']
['uc002ycq.2 ', 'uc001vnh.2']
['uc001odf.1 ', 'uc002mwd.2']
['uc010jkn.1 ', 'uc010luk.1']
['uc003uhf.3 ', 'uc010tqd.1']
['uc002rue.3 ', 'uc001tex.2']
['uc011dtt.1 ', 'uc001lkv.1']
['uc003yyt.2 ', 'uc003mkl.2']
['uc003pkv.2 ', 'uc003ytw.2']
['uc010bhz.2 ', 'uc002kbt.1']
['uc001wnj.2 ', 'uc009wtj.1']
['uc011lyh.1 ', 'uc003jvb.2']
['uc002awj.1 ', 'uc009znm.1']
['uc010bft.2 ', 'uc002cxz.1']
['uc011mar.1 ', 'uc001lvb.1']
['uc001oxl.2 ', 'uc002lvx.1']

I want to replace of the things after the dots, so I want to have  a file with 
this output:

['uc002uvo ', 'uc001mae']
['uc010dya ', 'uc001kko']
...

I try to use regular expression but I have  a strange output

with open("non_annotati.csv") as p:
    for i in p:
        lines= i.rstrip("\n").split("\t")
        mit = re.sub(r'(\.\d$)','',lines[0])
        mit2 = re.sub(r'(\.\d$)','',lines[1])
        print mit,mit2

uc003klv.2  uc010lxj
uc001tzy.2  uc011kzk
uc010qdj.1  uc001iku
uc004coe.2  uc002vmf
uc002dvw.2  uc004bxn
uc001dmp.2  uc001dmo
uc002rqd.2  uc010ynl
uc010cvm.1  uc002qjc
uc003ewy.3  uc003hgx
uc002ejy.2  uc003mvb
uc002fou.1  uc010ilx
uc003vhf.2  uc010qlo
uc003mix.2  uc010tdt
uc002nez.1  uc003wxe
uc011cpu.1  uc002keg
uc001ovu.2  uc011dne
uc010zfg.1  uc001jvq
uc010jlf.2  uc011azi
uc001ors.3  uc001vzx
uc010tyt.1  uc003vih
uc010fde.2  uc002xgq
uc010bit.1  uc003zle
uc010xcb.1  uc010wsg
uc011acg.1  uc009wlp
uc002bnj.2  uc004ckd

Where is the error? what is wrong in my regular expression code? 

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Gmane