Moving to Python From PHP: Using a variable in a function

2012-11-24  Source: Original Site  Category:Python  Views:0 


This is my first python script, so I could use a little bit of help here.

I'm using the 'Universal Feed Parser' (, and I have a list of feed URLs in a database which I would like to pull out and go through each of them. I am also using the ADOdb database module, as I am familier with it (in PHP .. however, it is pretty similar ..)

Here's what I have so far, the only thing this does is pulls the URLs out of the database, and prints them:

#!/usr/bin/env python

import MySQLdb
import adodb
import feedparser

conn = adodb.NewADOConnection('mysql')
cursor = conn.Execute('SELECT feed_url FROM feed_urls')

while not cursor.EOF:
for row in cursor.fields:
print row


As I said, this above code works perfectly. However, I want to take that output, and put it in something like this:

while not cursor.EOF:
for row in cursor.fields:
d = feedparser.parse(FEED_URL_HERE) <-- This is where I need the output of the db results to appear

So, basically .. the above code is calling a function from the 'Universal Feed Parser' module, which takes in a url .. basically, when it executes, I want python to read it like this:

d = feedparser.parse('')

I know it has got to be something simple. I'd definitely appreciate some help on this.

Related articles
  • Moving to Python From PHP: Using a variable in a function 2012-11-24

    This is my first python script, so I could use a little bit of help here. I'm using the 'Universal Feed Parser' (, and I have a list of feed URLs in a database which I would like to pull out and go through each of them. I am al

  • Selecting from database using a variable name 2015-05-01

    I am trying to use PHP to keep the results of a quiz in a database. I want to be able to record the total number of players, the total score, and the distribution of the scores from 1-20. I want to do this with one entry in a database with columns fo

  • Print datas coming from php using JS 2012-06-25

    how can i print datas coming from php <?php $x = //codes <script language="javascript"> document.write($x); </script> ?>

  • Using a variable value as function default value 2012-04-16

    Is it possible to use a value assigned to some variable as a function default value... what i mean is: function my_func( $var = $another_var){ ..... } if so, how?

  • Using sendAndLoad variables outside the function 2013-04-29

    This might seem like a silly problem to most of them but being a newbie I have been scratching my head over this. Can anybody tell me how can I get the value of uid in this code outside the function so that my other functions can use it too. I have t

  • Passing VARs to Python from PHP & capturing return string 2012-02-29

    My script doesn't want to recognize the variables from the exec() command in PHP. Plus, it won't capture the results of the script. This Python script works in IDLE, and I've got some testing code in there. I am cross posting in python-forum. One Kno

  • Ubuntu Executing Python from PHP, blank vars 2013-03-26

    Alright, so, I have a PHP file that's calling a Python script. I have confirmed this Python script works (in the CLI and in a seperate test PHP script), however it is not working here. The basic jist of this python script is, it accepts arguments and

  • retrieve and display single piece of data from row using a variable 2014-10-17

    OK I have made a little progress and now face something else. I will paste my code here. OK here goes. I am loading a php page from another page by clicking on a table row. This table is filled with data from mysql. When i click on a row I am sent to

  • Ubuntu send email from php (using pear) (no need to change php.ini) 2012-01-23

    I host a webpage from my PC, and I was having all kinds of issues trying to get it to send e-mails note: these steps send and receive the email through a gmail account. this (

  • accessing a table created from php with a variable name 2013-02-06

    Hi I need to select a table that's just been created and whose name is an ID number in a variable called $ID, like this mysql_query("CREATE TABLE `".$ID."` (`prenom` MEDIUMTEXT NOT NULL, `nom` MEDIUMTEXT NOT NULL,`email` MEDIUMTEXT NOT NULL, `fonctio

  • Help Needed: Incomplete string transfer from PHP to Javascript variable 2013-05-09

    When I output the data (string) of a php variable through javascript (client side) document.write() function, the string isn't output completely, rather only 152 characters are written. In usual string which I assign manually, I don't get this error.

  • SOAP: Call WSDL Service from PHP using NuSOAP 2014-07-20

    I'm building a web application on my Linux server using PHP and Java. I would like to call my web service deployed in Tomcat using PHP NuSOAP. I have the SOAP extension installed in PHP, I used the --enable-soap compile command (as well as many other

  • Moving Guest Book from PHP 4 to PHP 5 2014-10-29

    I am transferring an existing Guest Book from my old host that uses PHP 4.4.7 on to my new host that uses PHP 5.2.5 and I seem to be getting a connection error as a result of this. Both are using cPanel and the guest book is the PHP "Advanced Guestbo

  • Passing variables value from PHP to HTML variable 2014-10-31

    I hope this is the right forum. Have a HTML page that prompts user for information which is passed to a PHP file and it querys the database and it works fine. The next thing need to do is pass some of field values from the query to another HTML page.

  • insert an image with php using a variable 2015-02-12

    I'm not that good at php yet! Thought I would say that first. I'm having problems with inserting an image with a php variable. The variable just contains the picture name (not the extension or the directory etc) ?php require_once 'appinclude.php'; ec

  • Form design from PHP using Javascript 2013-09-15

    I have got a long list of items that are generated by PHP. There are 2000 more results and are constantly changing. What i am trying to do is all domains starting with A, B, C etc so it would hiden until you select A for example(sorta like a menu tre

  • using global variables in a function? 2013-01-04

    Ok, so I have an interface page with all the forms and everything and I have an include file that contains all the functions I use on the interface. I also have a session variable created called privilegeID when the user logs into the site and access

  • problem with using String Variable in IN Function 2014-07-08

    My problem is that I want to use a string variable in the 'where' clause Like this.I am using VB.6 dim ID as string ID = "('1','2')" Select coursecode from student where studentid in ID Now tell me how to solve this problem. or is there any other way

  • Using a variable in a function ? 2015-04-16

    I have a function in which I change a variable but I can not ssem to use it later on :o Here is the little function and the script: function doIt($img) { if !($hh1 = (@file_get_contents($img))) { $message2 = "This image is not good"; return; } // end

  • How to use a variable in init() function when it's declared in main 2013-03-05

    I have a program with arrays declared in the main function. However, when I want to use that array in my init() function, it doesn't work. May I know what must be done so that I can use my arrays in the init() function?