Closed GoogleCodeExporter closed 9 years ago
[deleted comment]
[deleted comment]
[deleted comment]
[deleted comment]
"I claim this task." That is, I'm assuming this task has not been claimed yet?
Oh,
and I might need some assistance completing:
http://rosettacode.org/rosettacode/w/index.php?title=XML_and_XPath
Original comment by average....@gmail.com
on 28 Nov 2007 at 7:06
Yes, average.programmer, this task is yours. Start with the parts you think
you can
complete on your own, then let us know if you get stuck on something.
Original comment by doug.hel...@gmail.com
on 28 Nov 2007 at 7:15
Re the XPath, there are several XPath-capable packages out there; use Google to
find
them. Contact us again if you run into trouble installing them.
Note that a conclusion that "XPath doesn't work properly in any of the available
Python XML parsing packages" is sufficient for task completion -- that's
important
information! However, actual code that fails should be given.
thanks!
Original comment by the.good...@gmail.com
on 28 Nov 2007 at 7:53
Original comment by doug.hel...@gmail.com
on 28 Nov 2007 at 11:58
Thanks to this issue, Python has now passed Perl as the language with the most
solved Rosetta Code tasks.
Good job!
http://www.rosettacode.org/rosettacode/w/index.php?title=Special:Mostlinkedcateg
ories
Original comment by i...@quirkster.com
on 29 Nov 2007 at 1:27
I have completed the task:
-------- Task 1:
>
http://rosettacode.org/rosettacode/w/index.php?title=Data_Representation_-_Contr
olling_Fields_in_a_Structure
>
# Controlling Fields in a Structure in Python
# This task is easily accomplished with the use of a Python dictionary.
rs232 = {
"PG Protective ground":1,
"TD Transmitted data":2,
"RD Received data":3,
"RTS Request to send":4,
"CTS Clear to send":5,
"DSR Data set ready":6,
"SG Signal ground":7,
"CD Carrier detect":8,
"+ voltage (testing)":9,
"- voltage (testing)":10,
"SCD Secondary CD":12,
"SCS Secondary CTS":13,
"STD Secondary TD":14,
"TC Transmit clock":15,
"SRD Secondary RD":16,
"RC Receiver clock":17,
"SRS Secondary RTS":19,
"DTR Data terminal ready":20,
"SQD Signal quality detector":21,
"RI Ring indicator":22,
"DRS Data rate select":23,
"XTC External clock":24
}
#assignation and retrieval of data is trivial
rs232["RD Received data"] = 1
print rs232["TC Transmit clock"]
-------- Task 2:
> http://rosettacode.org/rosettacode/w/index.php?title=Object_Serialization
# Object Serialization in Python
# serialization in python is accomplished via the Picke module. Alternatively,
one
can use the cPickle module if speed is the key, everything else in this example
remains the same
import pickle
class Entity:
def __init__(self):
self.name = "Entity"
def printName(self):
print self.name
class Person(Entity): #OldMan inherits from Entity
def __init__(self): #override constructor
self.name = "Cletus"
instance1 = Person()
instance1.printName()
instance2 = Entity()
instance2.printName()
target = file("objects.dat", "w") # open file
# ----- Serialize
pickle.dump((instance1, instance2), target) # serialize `instance1` and
`instance2`to
`target`
target.close() # flush file stream
print "Serialized..."
#----- Unserialize
target = file("objects.dat") # load again
i1, i2 = pickle.load(target)
print "Unserialized..."
i1.printName()
i2.printName()
-------- Task 3:
> http://rosettacode.org/rosettacode/w/index.php?title=XML_and_XPath
# Python has basic xml parsing built in
from xml.dom import minidom
xmlfile = file("test3.xml") # load xml document from file
xmldoc = xmldom.parse(xmlfile).documentElement # parse from file stream or...
xmldoc = xmldom.parseString("<inventory title="OmniCorp Store
#45x10^3">...</inventory>").documentElement # alternatively, parse a string
# 1st Task: Retrieve the first "item" element
i = xmldoc.getElementsByTagName("item") # get a list of all "item" tags
firstItemElement = i[0] # get the first element
# 2nd task: Perform an action on each "price" element (print it out)
for j in xmldoc.getElementsByTagName("price"): # get a list of all "price" tags
print j.childNodes[0].data # XML Element . TextNode . data of textnode
# 3rd Task: Get an array of all the "name" elements
namesArray = xmldoc.getElementsByTagName("name")
I would also like to make a few closing comments regarding the XML example.
I looked into pyxml v0.8.1, which seemed to be outdated, being only for Python
2.4
(Windows)
I looked into libxml2 and tried installing in my Python 2.5 (Windows)
Apparently it
didn't install correctly, see: http://users.skynet.be/sbi/libxml-python/
If I completed the task incorrectly, please don't hesitate to contact me so
that I
can fix it. Also, I've been in C++ too long, this task was a great opportunity
for me
to review Python. Thanks for the task!
Original comment by average....@gmail.com
on 29 Nov 2007 at 6:09
Nicely done.
Original comment by the.good...@gmail.com
on 29 Nov 2007 at 9:22
I expected the data structure example to use the struct module, since the
problem as
stated on rosettacode.org is talking about interfacing with devices and uses a
9 or
25 pin serial port as an example. All of the other implementations use
structures
with an appropriate number of bits.
Original comment by doug.hel...@gmail.com
on 29 Nov 2007 at 1:04
Hi, average.programmer, if you get a chance could you see about using the
struct module,
http://docs.python.org/lib/module-struct.html? The task is still complete but
it'd
be nice to have a more comparable solution to the other languages.
Original comment by the.good...@gmail.com
on 2 Dec 2007 at 8:01
Hello, I'll take another close look at the problem within the next day or so.
I've
used the struct module extensively before so it probably shouldn't be a
problem. :)
Original comment by average....@gmail.com
on 3 Dec 2007 at 7:54
Hi, I had a bit of extra time to turn around and look over the quality of my
completed tasks. As for the data structure example, would the _correct_ solution
amount to packing a list of strings with struct?
Original comment by average....@gmail.com
on 30 Jan 2008 at 3:26
Yep.
Original comment by the.good...@gmail.com
on 30 Jan 2008 at 7:03
I looked at the C example, which created a simple struct with one byte
allocated to
each element.
http://rosettacode.org/rosettacode/w/index.php?title=Data_Representation_-
_Controlling_Fields_in_a_Structure
So with Python struct it should be something like this?:
import struct
x = struct.pack("9c", '0','0','0','0','0','0','0','0','0')
I dunno, but it seems like a far cry from the other examples...
Original comment by average....@gmail.com
on 2 Feb 2008 at 8:30
Well, the RS-232 solution as it is now does not make much sense.
What does it mean for rs232["XTC External clock"] to have a value of 24?
I can see possibly using the structure you created, but assigning 0 to each
field to
initialize it.
If you are going to change the example to use struct, I have no insight as to
the
correctness of the struct code you posted. However you could certainly create a
function that allows the user to specify either field names or field numbers to
set /
reset the bits.
I'd much rather see a Python example that is correct and useful than one that
is short.
Original comment by miss...@hotmail.com
on 9 Feb 2008 at 9:42
Original issue reported on code.google.com by
the.good...@gmail.com
on 26 Nov 2007 at 6:26