Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1006855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:31:36+00:00 2026-05-16T08:31:36+00:00

I wrote a nice little app that gets Yahoo weather info and posts it

  • 0

I wrote a nice little app that gets Yahoo weather info and posts it to Twitter. It worked flawlessly and now I want to rearrange the code into differently named files so it makes more sense. And that’s when I hit some issues.

Previously, I had a Class in libtweather.py. It was my account. It allowed me to do accountName.parseFeed() and I’d get as output the parsed Yahoo weather. (__ini__ took the weather URL, twitter username and password as args)

This was accessed from my main script which created instances of the Class like this:
exec '%s = lw.twitterWeather("%s", "%s", "%s")' % (item[0], item[1], item[2], item[3])
It kept a list of all account names in a list which was passed as argument to the other functions.

Another function getWeather got weather by doing:

def getWeather(accountList): #account names passed as a list of strings
    for item in accountList:
        print item, ': ',
        item = eval(item)       
        print item.parseFeed(), '\n

I’ve decided now to move the getWeather function to the same file as the Class but the line item = eval(item)‘s giving me problems because there are no instances created in that file. All of them are in the main script.

Now my question: Is there some way I could give those instances as arguments to the function? Or must I put the function into the Class? Even if I did that, I’d still need to do the item.parseFeed() for multiple items in the list so I’d still need the item = eval(item), no?

Thanks in advance. My app’s a tad bit to post here in entirety, but I’ll post more code if needed to understand better.

Update: I ended up running my libtweather.py to create instances when it’s imported so that the functions inside it can access them (added the instance generating code at the bottom of the script). I’m sure there’s a better way but it works for me currently and I’m OK with that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:31:36+00:00Added an answer on May 16, 2026 at 8:31 am

    You should be using an explicit dict for storing these items. eval, exec, globals, locals, and vars are all horribly silly ways to do this poorly. Remember from the Zen of Python: “explicit is better than implicit.”

    feeds = {}
    for item in whatever:
        feeds[item[0]] = lw.twitterWeather(*item[1:])
    
    def getWeather(feeds, accountList):
        for item in accountList:
            print '%s: %s' % (item, feeds[item].parseFeed())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would having a nice little feature that makes it quicker to write code like
I wrote myself a little downloading application so that I could easily grab a
I wrote a windows service using VB that read some legacy data from Visual
I wrote a component that displays a filename, a thumbnail and has a button
I wrote a simple tool to generate a DBUnit XML dataset using queries that
I wrote an application that currently runs against a local instance of MySql. I
I've prototyped an iPhone app that uses (internally) SQLite as its data base. The
Hey, I've got this nice little piece of code, much like all the other
I wrote a python script that rotates an image 90 degrees. I am including
So I've got this nice little MVVM solution, and things work great. I've got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.