[Tutor] XML parsing when elements contain foreign characters

2014-01-09 Thread Garry Bettle
Howdy all,

Have you hear the news? Happy New Year!

Hope someone can help. I know this is a tutor list so please feel free to
send me somewhere else.

I'm trying to parse some XML and I'm struggling to reference elements that
contain foreign characters.

Code so far:

# -*- coding: utf-8 -*-

from xml.dom import minidom

xmldoc = minidom.parse('Export.xml')
products = xmldoc.getElementsByTagName('product')
print '%s Products' % len(products)

row_cnt = 0
titles = {}
stocklevel = {}
for product in products:
  row_cnt+=1
  title=product.getElementsByTagName('Titel')[0].firstChild.nodeValue
  stock=product.getElementsByTagName('AntalPåLager')[0].firstChild.nodeValue
  if title not in titles:
titles[title]=1
  else:
titles[title]+=1
  if stock not in stocklevel:
stocklevel[stock]=1
  else:
stocklevel[stock]+=1

Traceback (most recent call last):
  File "C:\Python27\Testing Zizzi.py", line 16, in 

stock=product.getElementsByTagName('AntalPÃ¥Lager')[0].firstChild.nodeValue
IndexError: list index out of range

I've tried to encode the string before giving it to getElementsByTagName
but no joy.

Any ideas?

Many thanks!

Cheers,

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


[Tutor] Python & Django

2014-01-09 Thread Rafael Knuth
Hej there,

I am very interested to hear your opinion on which version of Python
to use in conjunction with Django. Currently, I am taking a class at
Udemy and they recommend using Python 2.7 with Django 1.6. because
both versions work well with each other.

Over the last few months I got pretty much used to Python 3.3.0 which
some of you guys recommended to me on this mailing list. Hence, I
would prefer to keep using Python 3x but I am not sure if that's a
good idea. I heard of a couple folks using Python 3.3.0 with Django
1.6 that they ran into issues, and most of them switched back to
Python 2.7.

Your thoughts?
Thanks in advance!

All the best,

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


Re: [Tutor] Fwd: arrangement of datafile

2014-01-09 Thread Amrita Kumari
Hi,

Sorry for delay in reply(as internet was very slow from past two
days), I tried this code which you suggested (by saving it in a file):

import csv
with open('19162.csv') as f:
   reader = csv.reader(f)
   for row in reader:
  print(row)
  row[0] = int(row[0])
  key,value = item.split('=', 1)
  value = float(value)
  print(value)

and I got the output as:

C:\Python33>python 8.py
['2', 'ALA', 'C=178.255', 'CA=53.263', 'CB=18.411', '', '', '', '', '', '', '',
'', '', '']
Traceback (most recent call last):
  File "8.py", line 7, in 
key,value = item.split('=', 1)
NameError: name 'item' is not defined

my datafile is like this:

2,ALA,C=178.255,CA=53.263,CB=18.411,,
3,LYS,H=8.607,C=176.752,CA=57.816,CB=31.751,N=119.081
4,ASN,H=8.185,C=176.029,CA=54.712,CB=38.244,N=118.255
5,VAL,H=7.857,HG11=0.892,HG12=0.892,HG13=0.892,HG21=0.954,HG22=0.954,HG23=0.954,C=177.259,CA=64.232,CB=31.524,CG1=21.402,CG2=21.677,N=119.998
6,ILE,H=8.062,HG21=0.827,HG22=0.827,HG23=0.827,HD11=0.807,HD12=0.807,HD13=0.807,C=177.009,CA=63.400,CB=37.177,CG2=17.565,CD1=13.294,N=122.474
7,VAL,H=7.993,HG11=0.879,HG12=0.879,HG13=0.879,HG21=0.957,HG22=0.957,HG23=0.957,C=177.009,CA=65.017,CB=31.309,CG1=21.555,CG2=22.369,N=120.915
8,LEU,H=8.061,HD11=0.844,HD12=0.844,HD13=0.844,HD21=0.810,HD22=0.810,HD23=0.810,C=178.655,CA=56.781,CB=41.010,CD1=25.018,CD2=23.824,N=121.098
9,ASN,H=8.102,C=176.695,CA=54.919,CB=38.674,N=118.347
10,ALA,H=8.388,HB1=1.389,HB2=1.389,HB3=1.389,C=178.263,CA=54.505,CB=17.942,N=124.124,
--

where 1st element of each row is the residue no. but it is not
continuous (some are missing also for example the 1st row is starting
from resdiue no. 2 not from 1) second element of each row is the name
of amino acid and rest element of each row are the various atom along
with chemical shift information corresponding to that particular amino
acid for example H=8.388 is showing that atom is H and it has chemical
shift value 8.388. But the arrangement of these atoms in each row are
quite random and in few row there are many more atoms and in few there
are less. This value I got from Shiftx2 web server. I just want to
align the similar atom chemical shift value into one column (along
with residue no.) for example for atom C, it could be:

2 C=178.255
3 C=176.752
4  C=176.029
5 C=177.259
---
---

for atom H, it could be:

2 H=nil
3 H=8.607
4 H=8.185
5 H=7.857
6 H=8.062

---
and so on. So if a row doesn't have that atom (for ex. row 1 doesn't
have H atom) then if it can print nil that I can undestand that it is
missing for that particular residue. This arrangement I need in order
to compare this chemical shift value with other web server generated
program.

Thanks,
Amrita



and got the output as:

On 1/7/14, Steven D'Aprano  wrote:
> On Mon, Jan 06, 2014 at 04:57:38PM +0800, Amrita Kumari wrote:
>> Hi Steven,
>>
>> I tried this code:
>>
>> import csv
>> with open('file.csv') as f:
>>  reader = csv.reader(f)
>>  for row in reader:
>>  print(row)
>>  row[0] = int(row[0])
>>
>> up to this extent it is ok; it is ok it is giving the output as:
>>
>> ['1' , ' GLY' ,  'HA2=3.7850' ,  'HA3=3.9130' , ' ' , ' ' , ' ' , ' ']
>> [ '2' ,  'SER' ,  'H=8.8500' ,  'HA=4.3370' ,  'N=115.7570' , ' ' , ' ' ,
>> '
>> ']
>
> It looks like you are re-typing the output into your email. It is much
> better if you copy and paste it so that we can see exactly what happens.
>
>
>> but the command :
>>
>> key, value = row[2].split('=', 1)
>> value = float(value.strip())
>> print(value)
>>
>> is giving the value of row[2] element as
>>
>> ['1' , ' GLY' ,  'HA2=3.7850' ,  'HA3=3.9130' , ' ' , ' ' , ' ' , ' ']
>> 3.7850
>> [ '2' ,  'SER' ,  'H=8.8500' ,  'HA=4.3370' ,  'N=115.7570' , ' ' , ' ' ,
>> '
>> ']
>> 8.8500
>
> So far, the code is doing exactly what you told it to do. Take the third
> column (index 2), and split on the equals sign. Convert the part on the
> right of the equals sign to a float, and print the float.
>
>
>> so this is not what I want I want to print all the chemical shift value
>> of
>> similar atom from each row at one time
>
> Okay, then do so. You'll have to write some code to do this.
>
>
>> like this:
>>
>> 1 HA2=3.7850
>> 2 HA2=nil
>> 3 HA2=nil
>
> Where do these values come from?
>
>
>
>> .
>> 
>> ..
>> 13 HA2=nil
>>
>> similarly, for atom HA3:
>>
>> 1 HA3=3.9130
>> 2 HA3=nil
>> 3 HA3=nil
>> ...
>> 
>> 
>> 13 HA3=nil  and so on.
>>
>> so how to split each item into a key and a numeric value
>
> I've already shown you how to split an item into a key and numeric
> value. Here it is again:
>
> key, value = item.split('=', 1)
> value = float(value)
>
>
>> and then search
>> for similar atom and print its chemical shift value at one time along
>> with
>> residue no..
>
> I don't know what a chemical shift value a

[Tutor] help

2014-01-09 Thread Tihomir Zjajic

Please, can you help me convert this code from python 3 to python 2.6
g = input("Enter a vrs_drv:")
vrs_drv = int(g)

def vrs_drv():
   vrs_drv = input("Enter a vrs_drv:")
   if vrs_drv == "21":
   return("1")
   if vrs_drv == "22":
   return("2")
   if vrs_drv == "41":
   return("4")
number1 = vrs_drv()
print("kl_number1:",number1)

def prs_prec():
   prs_prec = input("Enter a prs_prec:")
   if prs_prec == "20":
   return("20")
   if prs_prec == "40":
   return("40")
   if prs_prec == "80":
   return("80")
number2 = prs_prec()
print("kl_number2:",number2)

def teh_kl():
   teh_kl = input("Enter a teh_kl:")
   if teh_kl == "1":
   return("1")
   if teh_kl == "2":
   return("2")
   if teh_kl == "3":
   return("3")
   if teh_kl == "4":
   return("4")
number3 = teh_kl()
print("kl_number3:",number3)

print(number1+number2+number3)
print("\n\nPress the enter key to exit.")

Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)]
on win32
Type "copyright", "credits" or "license()" for more information.

 RESTART



Enter a vrs_drv:21
Enter a vrs_drv:21
kl_number1: 1
Enter a prs_prec:40
kl_number2: 40
Enter a teh_kl:1
kl_number3: 1
1401


Press the enter key to exit.






Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)]
on win32







Type "copyright", "credits" or "license()" for more information.

   
   Personal firewall software may warn about the connection IDLE
   makes to its subprocess using this computer's internal loopback
   interface.  This connection is not visible on any external
   interface and no data is sent to or received from the Internet.
   

IDLE 2.6.5

 RESTART



Enter a vrs_drv:21
Enter a vrs_drv:21
('kl_number1:', None)
Enter a prs_prec:40
('kl_number2:', None)
Enter a teh_kl:2
('kl_number3:', None)

Traceback (most recent call last):
 File "C:/Users/Tihomir/Desktop/arcpadscript/send.py", line 39, in 
   print(number1+number2+number3)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'



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


Re: [Tutor] recursion depth

2014-01-09 Thread Steven D'Aprano
On Wed, Jan 08, 2014 at 06:16:03PM -0500, Dave Angel wrote:
> On Wed, 8 Jan 2014 16:23:06 -0500, eryksun  wrote:
> >On Wed, Jan 8, 2014 at 3:25 PM, Keith Winston  
> wrote:
> >> I've been playing with recursion, it's very satisfying.
> >>
> >> However, it appears that even if I sys.setrecursionlimit(10), 
> it blows
> >> up at about 24,000 (appears to reset IDLE). I guess there must be 
> a lot of
> >> overhead with recursion, if only 24k times are killing my memory?
> 
> I can't see the bodies of any of your messages (are you perchance 
> posting in html? ), 

I presume that your question is aimed at Keith.

Yes, Keith's emails have a HTML part and a text part. A half-decent mail 
client should be able to read the text part even if the HTML part 
exists. But I believe you're reading this from gmane's Usenet mirror, is 
that correct? Perhaps there's a problem with gmane, or your news client, 
or both.

Since this is officially a mailing list, HTML mail is discouraged but 
not strongly discouraged (that ship has sailed a long time ago, more's 
the pity...) so long as the sender includes a plain text part too. Which 
Keith does.

Keith, if you are able, and would be so kind, you'll help solve this 
issue for Dave if you configure your mail client to turn so-called "rich 
text" or formatted text off, at least for this mailing list.


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


Re: [Tutor] help

2014-01-09 Thread Steven D'Aprano
On Thu, Jan 09, 2014 at 09:52:04AM +0100, Tihomir Zjajic wrote:
> Please, can you help me convert this code from python 3 to python 2.6

Change input() to raw_input(). That will make it compatible with Python 
2.6. But that is not the cause of the error you get. The error that you 
get is that your functions don't always return a value.

For example, if you call prs_prec(), and enter 20, 40 or 80, it will 
return strings "20", "40" or "80". But if you enter 21, it returns 
nothing, or as Python does it, the special value None. Then, later in 
your program, you try to add None, and that doesn't work.

So look at your functions, and think about what they return.


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


Re: [Tutor] Python function argument passing problem

2014-01-09 Thread Alan Gauld

On 09/01/14 00:33, Manoj Rout wrote:


I have been working with python from last couple of weeks. As I am new
to python I have a problem with my work. So can you please look into the
below code.

with open('C:\\Users\\Manoj\\Desktop\\XMC1100_rm_v1.0.6_SVD.xml','r') as
xmlfile:

 svdlines = xmlfile.readlines()



Your indentation is way too big.
Reduce it to 2-4 spaces and it will be much more readable.
It may be an issue with your mail client but the current
spacing is hard to parse.
I've tried to bring it together but may have misaligned
some blocks in the process...




   def func_register(num):



Its usual to define functions outside of the program flow.
ie not inside the with statement. The definition of your
function does not depend on the context of the 'with'
so it can be placed outside.



for num,svdline in enumerate(svdlines):


You just hid the num parameter in your function definition.
Either change the name or lose the parameter.
Also since svdlines is the only global you reference you
should probably just pass it in as a parameter, it will
make your code more reusable.


if '' in svdline:
start = num+1

  break


for num,svdline in enumerate(svdlines[start:]):


If you never find 'register' above then start will not be set
and you will get an error. Its a good idea to initialize variables.

  if '' in svdline:
 end = num+1
 end = start+end

   break

count=0
for num,svdline in enumerate(svdlines[start:end]):

if '' in svdline:
count +=1
if count == 1:
   Registername = re.findall('name>([^ 
]*)<',svdline)

   print "Register Name is:",Registername
if '' in svdline:
OffsetAddress_SVD = 
re.findall('addressOffset>([^ ]*)<',svdline)

print "OffsetAddress is :",OffsetAddress_SVD
if '' in svdline:
resetvalue_SVD = re.findall('resetValue>([^ 
]*)<',svdline)

print "resetValue in SVD is :",resetvalue_SVD
end=end+1
print end



Here I want to define a recursive function func_register


It doesn't appear to be recursive? It never calls itself.


take the whole contents of file and file pointer position


I assume you mean num is the file pointer position?
If so you throw num away almost immediately in your for loop.
And you never return anything from the function.


iteration  and do the assigned work.


What is the "assigned work"? It doesn't seem to do anything
other than print a few values.

I assume in the following that by iterations you are
referring to the 3 for loops?


After first iteration  it will update the file pointer position


Its not doing that at the moment. It creates a new variable start.


Then in second iteration it should start from that particular

> position of that file .

Yes and it identifies the line after 

And the third loop does some testing and printing within
the defined range.


 I have written the above code and this
code will work if it is not inside the function. i. e outside the “def
func_register()”. So could you please help me iin this and also I have
added the file .


When you say it does not work what exactly happens?
Do you get an error message? If so please post it in its entirety
Do you get the wrong result? What did you expect what did you get?


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

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


Re: [Tutor] help

2014-01-09 Thread Alan Gauld

On 09/01/14 08:52, Tihomir Zjajic wrote:

Please, can you help me convert this code from python 3 to python 2.6


The main gotchas are that
1) input in Python 3 -> raw_input() in Python 2
2) print (XXX) in Python 3 -> print XXX in Python 2

Start from there then read any error messages and fix as needed.

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

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


Re: [Tutor] XML parsing when elements contain foreign characters

2014-01-09 Thread Steven D'Aprano
On Thu, Jan 09, 2014 at 09:50:24AM +0100, Garry Bettle wrote:

> I'm trying to parse some XML and I'm struggling to reference elements that
> contain foreign characters.

I see from your use of print that you're using Python 2. That means that 
strings '' are actually byte-strings, not text-strings. That makes it 
really easy for mojibake to creep into your program.

Even though you define a coding line for your file (UTF-8, well done!) 
that only effects how Python reads the source code, not how it runs the 
code. So when you have this line:

stock=product.getElementsByTagName('AntalPåLager')[0].firstChild.nodeValue

the tag name 'AntalPåLager' is a *byte* string, not the text that you 
include in your file. Let's see what Python does with it in version 2.7. 
This is what I get on my default system:

py> s = 'AntalPåLager'
py> print repr(s)
'AntalP\xc3\xa5Lager'

You might get something different.

What are those two weird escaped bytes doing in there, instead of å ? 
They come about because the string s is treated as bytes rather than 
characters. Python 2 tries really hard to hide this fact from you -- for 
instance, it shows some bytes as ASCII characters A, n, t, a, etc. But 
you can't escape from the fact that they're actually bytes, eventually 
it will cause a problem, and here it is:

> Traceback (most recent call last):
>   File "C:\Python27\Testing Zizzi.py", line 16, in 
>
> stock=product.getElementsByTagName('AntalPÃ¥Lager')[0].firstChild.nodeValue
> IndexError: list index out of range

See the tag name printed in the error message? 'AntalPÃ¥Lager'. That is 
a classic example of mojibake, caused by takes bytes interpreted in one 
encoding (say, UTF-8) and incorrectly interpreting them under another 
encoding (say, Latin-1).

There is one right way, and one half-right way, to handle text in Python 
2. They are:

- The right way is to always use Unicode text instead of bytes. Instead 
  of 'AntalPåLager', use the u prefix to get a Unicode string:

  u'AntalPåLager'


- The half-right way is to only use ASCII, and then you can get away 
  with '' strings without the u prefix. Americans and English almost 
  always can get away with this, so they often think that Unicode is a 
  waste of time.


My advise is to change all the strings in your program from '' strings 
to u'' strings, and see if the problem is fixed. But it may not be -- 
I'm not an expert on XML processing, and it may turn out that minidom 
complains about the use of Unicode strings. Try it and see.

I expect (but don't know for sure) that what is happening is that you 
have an XML file with a tag AntalPåLager, but due to the mojibake 
problem, Python is looking for a non-existent tag AntalPÃ¥Lager and 
returning an empty list. When you try to index into that list, it's 
empty and so you get the exception.


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


Re: [Tutor] Fwd: arrangement of datafile

2014-01-09 Thread Evans Anyokwu
First,  the error message means 'item' is missing. You will need to assign
your row as the item.

And if you want nil where there is no value, then use if statement to check
there is something otherwise make that empty value 'nil'.

Sorry, gotta run my train just arrived.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: arrangement of datafile

2014-01-09 Thread Dave Angel
On Thu, 9 Jan 2014 14:51:21 +0800, Amrita Kumari 
 wrote:
days), I tried this code which you suggested (by saving it in a 

file):





import csv
with open('19162.csv') as f:
   reader = csv.reader(f)
   for row in reader:
  print(row)
  row[0] = int(row[0])
  key,value = item.split('=', 1)
  value = float(value)
  print(value)



and I got the output as:



C:\Python33>python 8.py
['2', 'ALA', 'C=178.255', 'CA=53.263', 'CB=18.411', '', '', '', '', 

'', '', '',

'', '', '']


So you can see that row is a list representing one line of the data 
file. Clearly item is intended to be one element of the list, such as 
row[2] or row [3]. Try it first by adding just the line 
   item=row [2]


Then figure how to make a loop over the items in the row.

--
DaveA

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


Re: [Tutor] arrangement of datafile

2014-01-09 Thread Peter Otten
Amrita Kumari wrote:

> On 17th Dec. I posted one question, how to arrange datafile in a
> particular fashion so that I can have only residue no. and chemical
> shift value of the atom as:
> 1  H=nil
> 2  H=8.8500
> 3  H=8.7530
> 4  H=7.9100
> 5  H=7.4450
> 
> Peter has replied to this mail but since I haven't subscribe to the
> tutor mailing list earlier hence I didn't receive the reply, I
> apologize for my mistake, today I checked his reply and he asked me to
> do few things:

I'm sorry, I'm currently lacking the patience to tune into your problem 
again, but maybe the script that I wrote (but did not post) back then is of 
help.

The data sample:

$ cat residues.txt
1 GLY HA2=3.7850 HA3=3.9130
2 SER H=8.8500 HA=4.3370 N=115.7570
3 LYS H=8.7530 HA=4.0340 HB2=1.8080 N=123.2380
4 LYS H=7.9100 HA=3.8620 HB2=1.7440 HG2=1.4410 N=117.9810
5 LYS H=7.4450 HA=4.0770 HB2=1.7650 HG2=1.4130 N=115.4790
6 LEU H=7.6870 HA=4.2100 HB2=1.3860 HB3=1.6050 HG=1.5130 HD11=0.7690 
HD12=0.7690 HD13=0.7690 N=117.3260
7 PHE H=7.8190 HA=4.5540 HB2=3.1360 N=117.0800
8 PRO HD2=3.7450
9 GLN H=8.2350 HA=4.0120 HB2=2.1370 N=116.3660
10 ILE H=7.9790 HA=3.6970 HB=1.8800 HG21=0.8470 HG22=0.8470 HG23=0.8470 
HG12=1.6010 HG13=2.1670 N=119.0300
11 ASN H=7.9470 HA=4.3690 HB3=2.5140 N=117.8620
12 PHE H=8.1910 HA=4.1920 HB2=3.1560 N=121.2640
13 LEU H=8.1330 HA=3.8170 HB3=1.7880 HG=1.5810 HD11=0.8620 HD12=0.8620 
HD13=0.8620 N=119.1360

The script:

$ cat residues.py
def process(filename):
residues = {}
with open(filename) as infile:
for line in infile:
parts = line.split()# split line at whitespace
residue = int(parts.pop(0)) # convert first item to integer
if residue in residues:
raise ValueError("duplicate residue {}".format(residue))
parts.pop(0)# discard second item

# split remaining items at "=" and put them in a dict,
# e. g. {"HA2": 3.7, "HA3": 3.9}
pairs = (pair.split("=") for pair in parts)
lookup = {atom: float(value) for atom, value in pairs}

# put previous lookup dict in residues dict
# e. g. {1: {"HA2": 3.7, "HA3": 3.9}}
residues[residue] = lookup

return residues

def show(residues):
atoms = set().union(*(r.keys() for r in residues.values()))
residues = sorted(residues.items())
for atom in sorted(atoms):
for residue, lookup in residues:
print "{} {}={}".format(residue, atom, lookup.get(atom, "nil"))
print
print "---"
print

if __name__ == "__main__":
r = process("residues.txt")
show(r)

Note that converting the values to float can be omitted if all you want to 
do is print them. Finally the output of the script:

$ python residues.py 
1 H=nil
2 H=8.85
3 H=8.753
4 H=7.91
5 H=7.445
6 H=7.687
7 H=7.819
8 H=nil
9 H=8.235
10 H=7.979
11 H=7.947
12 H=8.191
13 H=8.133

---

1 HA=nil
2 HA=4.337
3 HA=4.034
4 HA=3.862
5 HA=4.077
6 HA=4.21
7 HA=4.554
8 HA=nil
9 HA=4.012
10 HA=3.697
11 HA=4.369
12 HA=4.192
13 HA=3.817

---

[snip]

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


Re: [Tutor] XML parsing when elements contain foreign characters

2014-01-09 Thread Stefan Behnel
Garry Bettle, 09.01.2014 09:50:
> I'm trying to parse some XML and I'm struggling to reference elements that
> contain foreign characters.

I skipped over Steven's response and he apparently invested quite a bit of
time in writing it up so nicely, so I can happily agree and just add one
little comment that you should generally avoid using MiniDOM for XML
processing. Instead, use the ElementTree library, which lives right next to
it in Python's standard library. It's a lot easier to use, and also
performs much better.

http://docs.python.org/library/xml.etree.elementtree.html

Stefan


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


Re: [Tutor] recursion depth

2014-01-09 Thread Dave Angel
On Thu, 9 Jan 2014 21:41:41 +1100, Steven D'Aprano 
 wrote:

I presume that your question is aimed at Keith.



Yes, Keith's emails have a HTML part and a text part. A half-decent 
mail 
client should be able to read the text part even if the HTML part 
exists. But I believe you're reading this from gmane's Usenet 
mirror, is 
that correct? Perhaps there's a problem with gmane, or your news 
client, 

or both.



Since this is officially a mailing list, HTML mail is discouraged 
but 
not strongly discouraged (that ship has sailed a long time ago, 
more's 
the pity...) so long as the sender includes a plain text part too. 
Which 

Keith does.


Yes I'm pretty sure it's Groundhog's fault. In tutor list, all I see 
of Keith ' messages is the 3-line footer. And in python.general I see 
nothing for such messages. 

I've used outlook express and Thunderbird and xpn for many years 
here. But a couple of months ago I switched to an android tablet,  
and "Groundhog newsreader" and "Android Usenet" have this problem 
with html here. I am using gmane,  but the other gmane sites don't 
have this problem.  Instead they show uninterpreted html on 
groundhog.  Those sites all happen to be googlegroups,  so that's 
another variable. 


Anybody know of an android solution?

--
DaveA

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


Re: [Tutor] recursion depth

2014-01-09 Thread Keith Winston
On Thu, Jan 9, 2014 at 5:41 AM, Steven D'Aprano  wrote:
>
> Keith, if you are able, and would be so kind, you'll help solve this
> issue for Dave if you configure your mail client to turn so-called "rich
> text" or formatted text off, at least for this mailing list.

Well, hopefully this is plain text. It all looks the same to me, so if
gmail switches back, it might go unnoticed for a while. Sorry for the
incessant hassle.


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


Re: [Tutor] Python & Django

2014-01-09 Thread Emile van Sebille

On 01/09/2014 01:13 AM, Rafael Knuth wrote:

Hej there,

I am very interested to hear your opinion on which version of Python
to use in conjunction with Django. Currently, I am taking a class at
Udemy and they recommend using Python 2.7 with Django 1.6. because
both versions work well with each other.

Over the last few months I got pretty much used to Python 3.3.0 which
some of you guys recommended to me on this mailing list. Hence, I
would prefer to keep using Python 3x but I am not sure if that's a
good idea. I heard of a couple folks using Python 3.3.0 with Django
1.6 that they ran into issues, and most of them switched back to
Python 2.7.

Your thoughts?



I'm sure the folks on the django list have the best opinions on this.

That said, the installation guide for django says 'It works with Python 
2.6, 2.7, 3.2 or 3.3' so I'd feel free to follow that unless I 
discovered that the areas giving problems would overlap with my specific 
use case.  If django by itself were at some level incompatible with 3.3 
the authors would have either already fixed it or removed 3.3 from the 
'known to work under' list, so I suspect it's still a third party module 
that the django users are having problems with.


YMMV,

Emile



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


Re: [Tutor] recursion depth

2014-01-09 Thread Dave Angel
On Thu, 9 Jan 2014 13:02:30 -0500, Keith Winston 
 wrote:
Well, hopefully this is plain text. It all looks the same to me, so 

if
gmail switches back, it might go unnoticed for a while. Sorry for 

the

incessant hassle.


That looks great,  thanks.

--
DaveA

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