Python - got dict, would rather object or list

Hey,
I've done PHP before and I like arrays, they're nice and to me, very easy to work with. Python, veeerrryyyy different. I'm slowly getting the hang of it but I want to do some changing here, I'm using a dictionary at the moment but in another section of code, it would be a lot easier if it were a list, and object would be easier than how I have it at the moment but a list is preferred.
Now I could rewrite it to use a  list (I think), but it would look insanely messy due to the need to define the variable as a list, eg.
var = []
var[0] = []
var[1] = []
In PHP terms, I'd like an array of arrays. Here is the code that makes a dict and is working, is there a neat and tidy way to rewrite this to create a list or something more managable?
def _loadServers(self, file):
# load servers
try:
f = open('servers.txt')
buf = f.read()
f.close()
except:
dPrint("error fetching server list")
if buf is not None:
lines = buf.split("n")
if lines[:-1] is None:
lines.pop( len(lines)-1 )
servers = {}
for server in lines:
i = len(servers)
servers[i] = {}
servers[i][0] = server.split(' ')[0]
servers[i][1] = server.split(' ')[1]
return servers
return False
and in case you want to see what I'm trying to do, the problem is later on, I'd like to remove a set from the "array", if it were a list I could use pop() which is better than setting the base key to None which is causing errors when in a different section of the code I loop over the array looking for subarrays.
def _removeServer(self, host):
for s in self.servers:
server = self.servers[ s ]
if server[1] == host:
self.servers[ s ] = None
return True
self._saveServers('servers.txt')
return False
That sounds really confusing actually, hope someone understands my dribble...
Thanks

you dont have to assign a list to each member of the original list.
define your list...
supalist = []
and when you wish to add to it,
suparlist.append(object)
where object is another list, variable, class, whatever you want.
iphitus
def _loadServers(self, file):
# load servers
try:
f = open('servers.txt')
buf = f.read()
f.close()
except:
dPrint("error fetching server list")
if buf is not None:
lines = buf.split("n")
if lines[:-1] is None:
lines.pop( len(lines)-1 )
servers = []
for server in lines:
splitserver = server.split()
servers.append([splitserver[0],splitserver[1])
return servers
return False

Similar Messages

  • I want to purchase Apature, but In the advertising blurb I dont see how to remove unwanted objects from a photo. I know it can be done in Adobe Elements, but I would rather Apature.

    I want to purchase Apature, but in the advertising blurb I dont see hoe to remove unwanted oblectsfrom a photo. I know it can be done in Adobe but I would rather have Apature.

    What DiploStrat said.
    To expand a little bit:  Aperture allows you to assign a graphics program (such as PSE) as an "external editor".  In general, you use Aperture to organize your photos, to develop them (make them as good as possible for each use), and to publish them (create share-able files).  Your external editor is used when you want to create a new graphics file, which is what happens in all "destructive pixel editing".
    Aperture provides tools to remove sensor spots from skies (and like operations), but for removing people and billboards you'll want a proper compositor, a/k/a a graphics program.

  • I've got FF ver 5. Love it . Took long time to "master it". If I download to ver 6 can I "fall back" to ver 5 if I decide i would rather not move to ver 6?

    As I asked in my question about "falling back" to ver 5 of FF. What if I download to ver 6 and decide I would rather remain with Firefox ver 5. In other words if I try the newest version of FF (6) and find it to much of a difference can I re-download FF v. 5? I'm kind of set with my current version and don't like the idea of changing to a newer version unless I have a fallback option.
    I will be waiting your answer. thanks---Ed R.

    Download a new copy of the Firefox program: http://www.mozilla.com/firefox/all.html
    Trash the current Firefox application to do a clean reinstall.
    Install the new version that you have downloaded.
    Your profile data is stored elsewhere in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder], so you won't lose your bookmarks and other personal data.

  • Has anyone got a script to read a list of email addresses from a Mail message and put them into a group in Contacts?

    Has anyone got a script to read a list of email addresses from a Mail message header and put them into a group in Contacts?

    Now Tony, I know you can't hear my tone on a forum post but I was not complaining, simply stating facts . This change brought several people in my office to a grinding halt in a long established workflow that is really rather simple (and I thought was already assumed from the original post above ):
    1) Select a set of records in FileMaker Pro 12 and export only their e-mail addresses as a CSV file.
    2) Open that CSV file in Excel.
    3) Copy the column of e-mail address.
    4) paste into the appropriate recipient field in Mail.
    5) Send
    If I were to complain it would be about Apple's typically opaque approach to updates. There is no granular explanation of why changes were made or even "what" changes were made.
    Complaining is futile since Apple is Apple and is unlikely to change, but sometimes it is cathartic to "shout into the void" .
    I had thought about doing something with a formula in Excel and your suggestion was simple and helpful. Again, however, it is only a workaround for a long established helpful behavior that Apple has inexplicably broken/removed in Mavericks Mail.
    I, and the other posters here, would love to have the capability back rather than have to add previously unneeded steps to our workflows.
    Ultimately we may add scripting steps to the FileMaker side to export the address lists with commas inserted already if Apple ends up having permanently removed this feature.

  • I cannot access my ebay account. I can still look for stuff but if I try to login in I get an error message saying that the connection was reset. This is the only site I am having issues with. The site works with IE6 but I would rather use Firefox.

    - Was having problems accessing messages on Facebook, seems to be working now
    - Cannot login on ebay.ca or ebay.com
    - Having troubles listing items on ebay (uploading pictures)... this started before the logging in problems
    - Problems only on laptop, other PC in the not having any problems
    - Can log in to ebay using IE on laptop, but I would rather use Firefox

    HouFunGuy wrote:
     One thing I notice is that the _mmServerScripts folder does not show up in my Local Files folder - even after refreshing. (The underscore must hide this folder?)When I change the drop-down from Local View to Testing Server I don't see the _mmServerScripts folder, and all folders are red.
    The underscore at the beginning of the folder name hides it in the Files panel, although you can turn on the option to display hidden files by accessing the panel options menu.
    The folder icons in the Files panel are colour coded: green is for local files, red represents the testing server (or Subversion repository, if defined), and yellow (Windows) or blue (Mac) represents your remote server.
    As Randy says, check the Web URL in your testing server definition. It should be http://localhost/check_php/.

  • Cannot Cast List ? extends Object as List Object

    I apologize if this is a common question but I could not seem to find the proper set of search terms that yielded an answer.
    Basically I have an RMI application and on the 'middle-tier' I would like to pass around references to the implementation objects and only convert to the interface type when dealing with them over RMI (I never pass an object back to the middle-tier).
    public interface Questionnaire implements Remote {
        public List<? extends Comment> getComments() throws RemoteException;
    public class QuestionnaireImpl extends UnicastRemoteObject implements Questionnaire {
        public List<CommentImpl> getComments() {...}
    }This works fine, the issue arises when I try to do the following:
    public List<Comment> getComments(int questionnaireId) throws RemoteException {
        return classLoader.getQuestionnaire(questionnaireId).getComments();
    }The compiler issues a Type mismatch: cannot convert from List<capture#8-of ? extends Comment> to List<Comment> Which I find perplexing as the compiler can assure that at the very least it is a List of Comment objects.

    public List<? extends Comment> getComments() throws RemoteException;
    public List<Comment> getComments(int questionnaireId) throws RemoteException {
    return classLoader.getQuestionnaire(questionnaireId).getComments();
    The compiler issues a Type mismatch: cannot convert from List<capture#8-of ? extends Comment> to List<Comment> Which I find perplexing as the compiler can assure that at the very least it is a List of Comment objects.Yes, however Java's generics work correctly to prevent you from shooting yourself in the foot. If you have a List<Superclass> pointing at a List<Subclass>, you would be entirely within your rights to try to store an object that is not castable to Subclass in it, this breaks type safety, so the compiler will not let you do it.
    Instead, create a new List<Supertype> and copy over the elements from the list returned by getComments(). There is a constructor that will do this for you.

  • Convert Object to List

    I have a method takes a Object and I need to convert it to List. What is the best way to do that?

    The same way you convert a thing to an apple.
    Either the thing is an apple, then you can help yourself by calling it "apple" instead of "thing" (namely casting the handling reference to the type "apple" --> Apple a = (Apple) theThing; ), or it isn't an apple at all and there's nothing you can do about it.
    If you cast, please do an instanceof check first. But I'd rather suggest passing List-type arguments right away if you can.

  • I have lost all my music on my itunes library. These were not purchased items from itunes, just CDs i had imported, so I could reimport them, but would rather not do that.

    I have recently lost all my itunes library. All the CD's were imported, but I would rather not go through the laborious technique of downloading them on to my computer again. I have tried all sorts of methods to restore my library, and have now given up. I have deleted itunes completely from my computer, and  reinstalled the program.
    I have now bought itunes match.
    Unfortunately, I now realise that I will lose all the music on my phone if I use itunes match. So, is there any way of transferring the music on my iphone back to itunes?
    Can anybody help?
    Thanks.

    Hey xxCreepyFiaxx,
    First, I would try the following suggested steps for when you don't see content in iTunes after updating:
    Quit iTunes.
    Download and install the latest version of iTunes.
    Use the Finder (Mac) or Windows Explorer (Windows) to go to the iTunes folder that contains the iTunes library files:
    Mac OS X
    /Users/username/Music/iTunes/
    Microsoft Windows Windows XP and Windows 2000
    \Documents and Settings\username\My Documents\My Music\iTunes\
    Microsoft Windows Windows Vista and Windows 7
    \Users\username\Music\iTunes\
    Drag the iTunes Library file from the above location to the Desktop.
    Open the Previous iTunes Libraries folder in the iTunes folder.
    Locate the file named iTunes Library YYYY-MM-DD where YYYY-MM-DD is the date you upgraded iTunes (Year-Month-Day).
    Drag this file to the iTunes folder (the enclosing folder).
    Rename this file to iTunes Library.
    Open iTunes.
    You should now see your missing content in iTunes.
    via: No content shows up in iTunes after updating
    http://support.apple.com/kb/TS1967
    If that doesn't resolve the issue, then I'd go through the steps in here:
    iTunes: Finding lost media and downloads
    http://support.apple.com/kb/TS1408
    Have a good one,
    Delgadoh

  • Does anyone know if Apple are planning on releasing a new version of the iPad in 2013? I want to buy one, but would rather wait to get the latest one if they are planning on a release of a newer version later this year.

    BEFORE JUST REJECTING MY QUERY, AS A POTENTIALLY NEW CUSTOMER I WOULD APPRECIATE SOME FORM OF AN ANSWER!!
    I want to buy an iPad (my first one), but would rather wait a couple of months to get the latest one if they are planning on a release of a newer version later this year. I certainly cannot afford to buy one now and then update when a newer model comes out, especially if it's released only a couple of months from now.

    The latest one came out just 4 months ago. Doubt one is coming out soon.
    There are always going to be people who are one day out of their return period when a new device comes out, and that's just that. No one can predict. And we are all just users here who would have no idea. But I would get an iPad now given the last one came out four months ago.

  • Is there anyway to take a downloaded app from one computer and put it on another without rebuying it. I have a macbook that I bought the new iMovie and iPhoto on, but I would rather it be on my iMac. So is there anyway I can change it?

    Is there anyway to take a downloaded app from one computer and put it on another without rebuying it. I have a macbook that I bought the new iMovie and iPhoto on, but I would rather it be on my iMac. So is there anyway I can change it? I thought that if I bought it the apps on my macbook, they would be avaliable on my imac like the mobile devices operate. The macbook has 10.6.8 cause its a older model and I think lion would slow it down. Any help??

    Just redownload it on the other computer by logging into the App Store with the same Apple ID you used to purchase it.

  • I have a brand new macbook with microsoft office loaded. I set outlook as the default mail. i would rather go back to mac mail but can't figure out how to do it. any ideas?

    I have a brand new macbook with microsoft office loaded. I set outlook as the default mail. i would rather go back to mac mail but can't figure out how to do it. any ideas?
    Thanks for any help
    Lou

    I have a similar problem: I switched from mac mail to Outlook 2011 as the default client, and want to switch back. Mailto links (eg from browser etc) default to Mail.  However, when I try to email a Word document as an attachment, it continues to open Outlook.  Outlook has a button in its prefs for making it the default client, but I don't see a way to turn this pref off in either Outlook or in Word.  

  • I HATE my new MACBOOK PRO, it will not let me open any PDF files and I downloaded the ADOBE READER three freaking times and it keeps saying that all the files are corrupt. I would rather have my 2008 Dell at this point. what is wrong with this thing

    I HATE my new MACBOOK PRO, it will not let me open any PDF files and I downloaded the ADOBE READER three freaking times and it keeps saying that all the files are corrupt or damaged. I would rather have my 2008 Dell at this point. what is wrong with this thing

    Perhaps the PDF files are corrupted.
    Hit the command key and spacebar, a blue Spotlight in the upper right hand corner appears, now type Preview and press return on the Preview program.
    Now you can try opening the PDF's from the file menu and see what's going on.
    If they are corrupted, perhaps they are trojans from your Windows PC or gotten from a bad location online.
    Download the free ClamXav and run a scan on the possibly infected folder.

  • How can I force mount a dvd that isn't even seen by Disk Utility? I can see it on the Mac when using my Windows 7 partition via Boot Camp, but not in Lion, which is how I would rather be running.

    How can I force mount a dvd that isn't even seen by Disk Utility? I can see it on the Mac when using my Windows 7 partition via Boot Camp, but not in Lion, which is how I would rather be running.

    Well if there is a EFI block, then running a program in OS X isn't going to do a lick of good.
    After all EFI was designed for Trusted Computing and Digital Rights Management, to act between the OS and hardware, can read drives, contact the Internet and everything.
    Windows doesn't use EFI, will have UEFI in Windows 8 though.

  • Services for Objects Attachement List Display Note not Viewable

    Hi Experts!
    Good day! I'm trying to display a note in FK03 (related to Services for Objects - Attachment List) and I only see white screen pop up window. No message and text information. When I tried to use another PC I can successfully view it.
    Is there's a plugin that I may need to install?
    Your help will be greatly appreciated.

    Hi Marty
    It is my understanding that the IXOS licensing is based on users retrieving of documents not necessarily the viewer so the licensing implications of having non-IXOS viewers accessing documents using the generic archivelink viewer is still likely to result in licensing implications if an audit is conducted at any stage.
    The transaction for specifying the viewer is the OAA3 and OAG4.
    Regards,
    Athol

  • Does anyone know how well the Intel Iris Pro installed on new 15" MacBook Pros performs using Photoshop and Lightroom. I have seen some differing opinions out there, and I would rather not shell out the extra cash for the Nvidia if I don't have to. I most

    Does anyone know how well the Intel Iris Pro installed on new 15" MacBook Pros performs using Photoshop and Lightroom?  I have seen some differing opinions out there, and I would rather not shell out the extra cash for the Nvidia if I don't have to. I mostly do photo editing for business and personal use. I have not used the 3D function in Photoshop, but I would like to know that I could.

    You could download a trial and see how well it works before committing to a subscription. You get 30 days to decide.
    Photo editor | Download free Adobe Photoshop CC trial
    Photo editor app | Download free Adobe Photoshop Lightroom 5 trial
    Gene

Maybe you are looking for

  • What happens if i activate a deactivated site?

    Hello! We're using crm 4.0 with sp 4 on an oracle system. We've a very big site for a workgroup server. This site was deactivated since one day. Now we want to activate this site again wondering what will happen We don't want much traffic like we'll

  • SL to Lion - can't run ML

    I have a Macbook (April 2008 model) which can run Lion but not Mountain Lion. I would like to use iBooks Author which requires Lion and there are a couple of photography apps which also require 10.7 - and I see that there may be security concerns wit

  • Is there a good white balance plug-in for Premiere Elements?

    Now that I've discovered and installed the Mercalli V2 Stabilizer plug-in (wow, is it great!), I think that the only thing lacking in Premiere Elements 10 is a plug-in to correct white balance. What I'm talking about is a simple warmer / cooler tempe

  • Adobe iFilter 6 with MS indexing service on asian language

    Hi All: I found the search hit for iFilter 6 on Win2003 (ENG) is much lower than on Win2000 (ENG) with indexing service. (I am testing on Tradition Chinese Characters search). In addition, iFilter is not bundle on Acrobat Reader 8.X, but it show no i

  • Problem regarding po condition

    Hiii experts... user created a po and entering a condtion r002(Absolute discount) ... now when she enters rs 01.60 directly for discount... its calculates 11.20 ... i checked m/06 and m/08 ... its same as development server and in development server.