Data entry into variables



  • I want to record information in the variable and then keep it in the file.

    There's a code:

    import wmi
    c = wmi.WMI ()
    DRIVE_TYPES = {
      0 : "Unknown",
      1 : "No Root Directory",
      2 : "Removable Disk",
      3 : "Local Disk",
      4 : "Network Drive",
      5 : "Compact Disc",
      6 : "RAM Disk"
    }
    

    for drive in c.Win32_LogicalDisk ():
    print drive.Caption, DRIVE_TYPES[drive.DriveType]

    which prints at launch

    C: Local Disk
    D: Local Disk
    E: Compact Disc
    F: Compact Disc
    G: Compact Disc

    It's okay. But when I'm recording information to the variable and then I'm trying to get the information out of it, that's the thing. (u'G:', 'Compact Disc') And that's it.
    I don't understand. What's going on?

    C: Local Disk
    D: Local Disk
    E: Compact Disc
    F: Compact Disc
    G: Compact Disc

    It's not a list, not a dictionary, not a line.



  • The point is, when a comma is assigned, it's recognized as a cortex designer (tuple). If I understand correctly, you're trying to fulfil the following phrase:

    value = drive.Caption, DRIVE_TYPES[drive.DriveType]
    

    It's equivalent.

    value = (drive.Caption, DRIVE_TYPES[drive.DriveType])
    

    Cortege can be counted as an inexorable list. It's on the screen right in the format you indicated.

    You're getting a different picture in the press, because the operator's comma. print is not a cortic designer, but simply separates the operator ' s arguments. Values transferred to the operator print They're transforming into a string performance and splitting gaps, which is why you see a convenient performance for you.

    If you want a line of view C: Local Disk, this can be done by using a formatting line:

    value = u'{} {}'.format(drive.Caption, DRIVE_TYPES[drive.DriveType])
    print value    #  C: Local Disk
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2