473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Should I learn Python instead?

Hi guys,

I'm a student/hobbyist programmer interested in creating a web project.
It's nothing too complicated, I would like to get data from an RSS
feed and store that into a database. I want my website to get the
information from the database and display parts of it depending on the
criteria I set.

I just finished an OO programming class in Java and I thought it would
be a good idea to do this in C# since ASP.NET makes web applications
easier than using Java (that's what I've heard anyway). I thought it
would be easy to pick up since the language syntax is very similar but
I'm getting overwhelmed by the massive class library. MSDN docs are
very good and thorough but the language just seems a little unwieldy
and too verbose.

This is how to access an RSS feed and create an XML document to
manipulate it.

System.Net.WebRequest myRequest = System.Net.WebRequest.Create("//feed
url here");
System.Net.WebResponse myResponse = myRequest.GetResponse();
System.IO.Stream rssStream = myResponse.GetResponseStream();
System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument();

rssDoc.Load(rssStream);

Here's PHP.

$rss_feed = file_get_contents($rss_url);

I realize that learning the library is part of the process, but as a
beginner I appreciate simplicity. Is Python easier than C#? Can
someone show how to access an XML document on the web and have it ready
to be manipulated for comparison? Any other advice for a newbie?

Thanks.

Apr 14 '06 #1
7 2093
First of all, let me tell you that you can now write apps for .NET with
Python.
There's a python implementation for the .NET framework called
Ironpython (in beta 5 now).

Regarding XML, I can't tell you much but in general, python is much
easier, cleaner, concise and intuitive than all the other alternatives
you mention.
Being a dynamic language, you can achieve more with less lines of code.

Easy tasks are easier with python, and complex tasks can look simple
with too.

I also think that Python is an excellent first language to learn.
Learn it, get used to think as a programmer, learn the basics
(functions classes, oop.) and then, when you're reasonably comfortable,
you'll be ready to pick any other language (or you'll be happy enough
to know that you don't need to learn any other one).

Apr 14 '06 #2
ej

"fyleow" <fy****@gmail.com> wrote :

<snip>
I realize that learning the library is part of the process, but as a
beginner I appreciate simplicity.
Is Python easier than C#? Absolutely.
Can someone show how to access an XML document on the web and have it ready to be manipulated for comparison? Yes. (see below)
Any other advice for a newbie? Learn Python. It's good to know other languages too, but when it comes to
getting stuff done fast & cleanly, you will find Python an invaluable tool.

# here's a simple use of the urllib module to fetch a document from the web
(output from an interactive python interpreter session): python Python 2.3.4 (#1, Feb 7 2005, 15:50:45)
[GCC 3.3.4 (pre 3.3.5 20040809)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import urllib
url = 'http://www.google.com'
fd = urllib.urlopen(url)
html = fd.read()
print html <html><head><meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1"><title>Google</title><style>
....
<snip>
I don't use RSS myself, and don't happen to know a url that gets me to an
RSS document, but here's an RSS document I found at:
http://www.xml.com/pub/a/2002/12/18/dive-into-xml.html

Here's just the document itself:

<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"

<channel rdf:about="http://www.xml.com/cs/xml/query/q/19">
<title>XML.com</title>
<link>http://www.xml.com/</link>
<description>XML.com features a rich mix of information and services for
the XML community.</description>
<language>en-us</language>
<items>
<rdf:Seq>
<rdf:li
rdf:resource="http://www.xml.com/pub/a/2002/12/04/normalizing.html"/>
<rdf:li
rdf:resource="http://www.xml.com/pub/a/2002/12/04/som.html"/>
<rdf:li
rdf:resource="http://www.xml.com/pub/a/2002/12/04/svg.html"/>
</rdf:Seq>
</items>
</channel>
<item rdf:about="http://www.xml.com/pub/a/2002/12/04/normalizing.html">
<title>Normalizing XML, Part 2</title>
<link>http://www.xml.com/pub/a/2002/12/04/normalizing.html</link>
<description>In this second and final look at applying relational
normalization techniques to W3C XML Schema data modeling, Will Provost
discusses when not to normalize, the scope of uniqueness and the fourth and
fifth normal forms.</description>
<dc:creator>Will Provost</dc:creator>
<dc:date>2002-12-04</dc:date>
</item>
<item rdf:about="http://www.xml.com/pub/a/2002/12/04/som.html">
<title>The .NET Schema Object Model</title>
<link>http://www.xml.com/pub/a/2002/12/04/som.html</link>
<description>Priya Lakshminarayanan describes in detail the use of the
..NET Schema Object Model for programmatic manipulation of W3C XML
Schemas.</description>
<dc:creator>Priya Lakshminarayanan</dc:creator>
<dc:date>2002-12-04</dc:date>
</item>
<item rdf:about="http://www.xml.com/pub/a/2002/12/04/svg.html">
<title>SVG's Past and Promising Future</title>
<link>http://www.xml.com/pub/a/2002/12/04/svg.html</link>
<description>In this month's SVG column, Antoine Quint looks back at
SVG's journey through 2002 and looks forward to 2003.</description>
<dc:creator>Antoine Quint</dc:creator>
<dc:date>2002-12-04</dc:date>
</item>
</rdf:RDF>

Here's a separate interpreter session where I have put the document above
into a string called xml:

This is the important, functional part:
from xml.dom import minidom
doc = minidom.parseString(xml)
The rest of what follows is just me poking around at the document structure.
You can write whatever code you need to get what you want:
doc.firstChild <DOM Element: rdf:RDF at 0x404a56ac> c1 = doc.firstChild
c1.getElementsByTagName('dc:date') [<DOM Element: dc:date at 0x404acc6c>, <DOM Element: dc:date at 0x404acfec>,
<DOM Element: dc:date at 0x404db38c>] c1.getElementsByTagName('dc:date')[0].toxml() u'<dc:date>2002-12-04</dc:date>' date = c1.getElementsByTagName('dc:date')[0]
date.nodeValue
date.hasChildNodes <bound method Element.hasChildNodes of <DOM Element: dc:date at 0x404acc6c>> date.hasChildNodes() True date.firstChild <DOM Text node "2002-12-04"> dir(date.firstChild) ['ATTRIBUTE_NODE', 'CDATA_SECTION_NODE', 'COMMENT_NODE',
'DOCUMENT_FRAGMENT_NODE', 'DOCUMENT_NODE', 'DOCUMENT_TYPE_NODE',
'ELEMENT_NODE', 'ENTITY_NODE', 'ENTITY_REFERENCE_NODE', 'NOTATION_NODE',
'PROCESSING_INSTRUCTION_NODE', 'TEXT_NODE', 'TREE_POSITION_ANCESTOR',
'TREE_POSITION_DESCENDENT', 'TREE_POSITION_DISCONNECTED',
'TREE_POSITION_EQUIVALENT', 'TREE_POSITION_FOLLOWING',
'TREE_POSITION_PRECEDING', 'TREE_POSITION_SAME_NODE', '__doc__', '__len__',
'__module__', '__nonzero__', '__repr__', '__setattr__',
'_call_user_data_handler', '_get_childNodes', '_get_data',
'_get_firstChild', '_get_isWhitespaceInElementContent', '_get_lastChild',
'_get_length', '_get_localName', '_get_nodeValue', '_get_wholeText',
'_set_data', '_set_nodeValue', 'appendChild', 'appendData', 'attributes',
'childNodes', 'cloneNode', 'data', 'deleteData', 'firstChild',
'getInterface', 'getUserData', 'hasAttributes', 'hasChildNodes',
'insertBefore', 'insertData', 'isSameNode', 'isSupported',
'isWhitespaceInElementContent', 'lastChild', 'length', 'localName',
'namespaceURI', 'nextSibling', 'nodeName', 'nodeType', 'nodeValue',
'normalize', 'ownerDocument', 'parentNode', 'prefix', 'previousSibling',
'removeChild', 'replaceChild', 'replaceData', 'replaceWholeText',
'setUserData', 'splitText', 'substringData', 'toprettyxml', 'toxml',
'unlink', 'wholeText', 'writexml'] date.firstChild.wholeText u'2002-12-04'
# call dir() and help() on your doc and various other things to see what is
available.
# for example
dir(c1)

['ATTRIBUTE_NODE', 'CDATA_SECTION_NODE', 'COMMENT_NODE',
'DOCUMENT_FRAGMENT_NODE', 'DOCUMENT_NODE', 'DOCUMENT_TYPE_NODE',
'ELEMENT_NODE', 'ENTITY_NODE', 'ENTITY_REFERENCE_NODE', 'NOTATION_NODE',
'PROCESSING_INSTRUCTION_NODE', 'TEXT_NODE', 'TREE_POSITION_ANCESTOR',
'TREE_POSITION_DESCENDENT', 'TREE_POSITION_DISCONNECTED',
'TREE_POSITION_EQUIVALENT', 'TREE_POSITION_FOLLOWING',
'TREE_POSITION_PRECEDING', 'TREE_POSITION_SAME_NODE', '__doc__', '__init__',
'__module__', '__nonzero__', '__repr__', '_attrs', '_attrsNS',
'_call_user_data_handler', '_child_node_types', '_get_attributes',
'_get_childNodes', '_get_firstChild', '_get_lastChild', '_get_localName',
'_get_tagName', '_magic_id_nodes', 'appendChild', 'attributes',
'childNodes', 'cloneNode', 'firstChild', 'getAttribute', 'getAttributeNS',
'getAttributeNode', 'getAttributeNodeNS', 'getElementsByTagName',
'getElementsByTagNameNS', 'getInterface', 'getUserData', 'hasAttribute',
'hasAttributeNS', 'hasAttributes', 'hasChildNodes', 'insertBefore',
'isSameNode', 'isSupported', 'lastChild', 'localName', 'namespaceURI',
'nextSibling', 'nodeName', 'nodeType', 'nodeValue', 'normalize',
'ownerDocument', 'parentNode', 'prefix', 'previousSibling',
'removeAttribute', 'removeAttributeNS', 'removeAttributeNode',
'removeAttributeNodeNS', 'removeChild', 'replaceChild', 'schemaType',
'setAttribute', 'setAttributeNS', 'setAttributeNode', 'setAttributeNodeNS',
'setIdAttribute', 'setIdAttributeNS', 'setIdAttributeNode', 'setUserData',
'tagName', 'toprettyxml', 'toxml', 'unlink', 'writexml']
# See also: http://docs.python.org/lib/module-xml.dom.minidom.html

There may well be other, more specialized Python modules just for doing
RSS - check around and at the Python Cheese Shop: http://www.python.org/pypi

HTH,
-ej


Apr 14 '06 #3
fyleow wrote:
Hi guys,

I'm a student/hobbyist programmer interested in creating a web project.
It's nothing too complicated, I would like to get data from an RSS
feed and store that into a database. I want my website to get the
information from the database and display parts of it depending on the
criteria I set.

I just finished an OO programming class in Java and I thought it would
be a good idea to do this in C# since ASP.NET makes web applications
easier than using Java (that's what I've heard anyway). I thought it
would be easy to pick up since the language syntax is very similar but
I'm getting overwhelmed by the massive class library. MSDN docs are
very good and thorough but the language just seems a little unwieldy
and too verbose.

This is how to access an RSS feed and create an XML document to
manipulate it.

System.Net.WebRequest myRequest = System.Net.WebRequest.Create("//feed
url here");
System.Net.WebResponse myResponse = myRequest.GetResponse();
System.IO.Stream rssStream = myResponse.GetResponseStream();
System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument();

rssDoc.Load(rssStream);

Here's PHP.

$rss_feed = file_get_contents($rss_url);

Here is Python (including printing all titles in the feed):

import urllib
import elementtree.ElementTree as ET

feed = ET.parse(urllib.urlopen("http://www.python.org/channews.rdf"))
for item_title in feed.findall("channel/item/title"):
print item_title.text

elementtree library is available here:
http://effbot.org/zone/element-index.htm
I realize that learning the library is part of the process, but as a
beginner I appreciate simplicity. Is Python easier than C#?
Developers of Python try to make it simple and powerful, so in general
Python is easier to use, but you may hit corner cases.

Any other advice for a newbie?


Sometimes open source documentation is harder to understand than
documentation for commercial libraries. In such cases I usually walk
over all functions in the library trying them, getting familiar with
the library's jargon. So the learning curve is more steep but when
you're on the top things are much easier.

Serge

Apr 14 '06 #4
Thanks guys. I picked up the Apress book on Python and downloaded the
Komodo IDE trial to get me started.

I'm going to try using Django to build my website and since my brother
already has hosting I'll just borrow some space.
He does PHP for a living, so it would probably be better for me to use
that instead.

Unfortunately, I'm allergic to dollar signs ;)

Apr 15 '06 #5
fyleow wrote:
Hi guys,

I'm a student/hobbyist programmer interested in creating a web project.
It's nothing too complicated, I would like to get data from an RSS
feed and store that into a database. I want my website to get the
information from the database and display parts of it depending on the
criteria I set.
[...]
This is how to access an RSS feed and create an XML document to
manipulate it.

System.Net.WebRequest myRequest = System.Net.WebRequest.Create("//feed
url here");
System.Net.WebResponse myResponse = myRequest.GetResponse();
System.IO.Stream rssStream = myResponse.GetResponseStream();
System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument();

rssDoc.Load(rssStream);

Here's PHP.

$rss_feed = file_get_contents($rss_url);

I've never used it myself but maybe this would be useful:

http://feedparser.org/
From the Homepage:

import feedparser
d = feedparser.parse("http://feedparser.org/docs/examples/atom10.xml")
d.feed.title u'Sample Feed' d.channel.title u'Sample Feed' d.feed.link u'http://example.org/' d.feed.subtitle # parses escaped HTML u'For documentation <em>only</em>' d.channel.description

u'For documentation <em>only</em>'

Gerard

Apr 15 '06 #6
There is also TurboGears, which (IMO) is greatness in the making.
Though unfortunately, the documentation is still catching up to the
greatness. I'm using it and loving it, though.

http://www.turbogears.org

DJango is great for content management. TurboGears is (IMO) a more
generalized framework. It all depends on what kind of site you are
wanting to create.

Apr 15 '06 #7
"fyleow" <fy****@gmail.com> writes:
I'm a student/hobbyist programmer interested in creating a web project.
I'm a student too and I've done a little Python web related stuff long ago.
It's nothing too complicated, I would like to get data from an RSS
feed and store that into a database. I want my website to get the
information from the database and display parts of it depending on the
criteria I set.
That's a really easy thing to do. You're lucky because thanks to Mark Pilgrim
we have one of the best RSS/Atom parsing libraries out there:
http://feedparser.org/

It's quite simple:

1 - you parse the feed
2 - you take the data
3 - you display them in your html page with one of the python frameworks
available.
I just finished an OO programming class in Java and I thought it would
be a good idea to do this in C# since ASP.NET makes web applications
easier than using Java (that's what I've heard anyway).
It's quite right. ASP.NET is easier than JSP and J2EE stuff but Python is
better to me :)
I thought it
would be easy to pick up since the language syntax is very similar but
I'm getting overwhelmed by the massive class library. MSDN docs are
very good and thorough but the language just seems a little unwieldy
and too verbose.
Yeah they like in that way. A 40000+ class library and gigatons of
documents. All is verbose in their static world: documents, books, languages :(
This is how to access an RSS feed and create an XML document to
manipulate it.
I know the author of the RSS.NET library and I used it in the past, it can save
you some machinery. But why get a bad language with a good library instead of a
wonderful library and a very good language :) ?
Is Python easier than C#?
IMHO yes.
Can
someone show how to access an XML document on the web and have it ready
to be manipulated for comparison? Any other advice for a newbie?


Start with the examples on the feedparser homepage. Then choose a framework
(Turbogears? CherryPy?) and then it's a matter of _minutes_ to have a HTML page
filled with your data.

--
Lawrence - http://www.oluyede.org/blog
"Nothing is more dangerous than an idea
if it's the only one you have" - E. A. Chartier
Apr 17 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: python | last post by:
Hello folks, I have been programming with Perl then with Python for about 7 years. But I have heard a lot of praise about PHP but I would like to know what is so nice with PHP and if it is worth...
14
by: Sam | last post by:
Hi, I have been developing sites and cms's for the past few years using PHP and mysql. I've been interested in learning a new language and was considering Python. I have a pretty decent grasp of...
24
by: Christopher J. Bottaro | last post by:
This post is just the culmination of my thoughts and discussions with my coworkers on Python. If you are not interested, please skip over it. At my work, we are developing a product from...
21
by: TAM | last post by:
Hi, I read that ASP.NET uses VB.NET instead of VBScript. I also read that ASP.NET is a subset of VB.NET. So if I learn VB.NET first then do I have the knowledge for programming ASP.NET...
7
by: Max | last post by:
On monday I start a semester course in Python (the alternative was Java). I was looking through the course outline and noticed the following: 1) UserDict is used. This is deprecated, right? 2)...
65
by: Chris Carlen | last post by:
Hi: From what I've read of OOP, I don't get it. I have also found some articles profoundly critical of OOP. I tend to relate to these articles. However, those articles were no more objective...
28
by: windandwaves | last post by:
Can someone tell me why I should learn python? I am a webdeveloper, but I often see Python mentioned and I am curious to find out what I am missing out on. Thank you Nicolaas
16
by: Raxit | last post by:
Hi, i was reading/learning some hello world program in python. I think its very simillar to Java/C++/C#. What's different (except syntax) ? what can i do easily with python which is not easy...
0
by: Sells, Fred | last post by:
write working programs
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.