0

I am new to Python, so I need a little guidence. I have a php file that I am porting over into python and can't seem to find a good way to convert the following php array into a python array or list. I did some research and found that python list are better.

PHP array (names from sql query)

$heads = array(
'ServerHostID' => 'ServerHostID',
'SERVER_NAME' => 'Server Name',
'SERVER_NUMBER' => 'Server Number',
'SERVER_OPERATIONAL_STATUS' => 'Server Operational Status',
'HOST_NAME' => 'Host Name',
'HOST_NUMBER' => 'Host Number',
'ALIAS' => 'Alias',
'UTILIZATION_PERCENTAGE' => 'Utilization Percentage',
'DATA_SIZE' => 'Data Size',
'HAS_REMOTE_ACCESS' => 'Has Remote Access',
'CLUSTER' => 'Cluster',
'VM_NAME' => 'VM Name',
'VM_IP_ADDRESS' => 'VM IP Address',
'CPU_ALLOCATED' => 'CPU Allocated',
'MEMORY_ALLOCATED' => 'Memory Allocated',
'IS_VIRTUAL' => 'Is Virtual',
'LOGICAL_PARTITION' => 'Logical Partition',
'PHYSICAL_PARTITION' => 'Physical Partition',
'OPERATING_SYSTEM_SOFTWARE' => 'Operating System Software',
'OPERATIONAL_USE' => 'Operational Use',
'FUNCTIONAL_USE' => 'Functional Use',
'HOST_OPERATIONAL_STATUS' => 'Host Operational Status'
);

Thank you for your help!

3 Answers 3

3

Err, no. You want a dict.

heads = {
  'ServerHostID': 'ServerHostID',
  'SERVER_NAME': 'Server Name',
   ...
}
Sign up to request clarification or add additional context in comments.

Comments

2

Use dictionary in python.

>>> heads = {'ServerHostID' : 'ServerHostID','SERVER_NAME' : 'Server Name'}
>>> heads['ServerHostID']
'ServerHostID'
>>>

Comments

2

You should use a dictionary instead of a list, since they are the "replacement" of "associative arrays" in Python.

{'ALIAS': 'Alias',
 'CLUSTER': 'Cluster',
 'CPU_ALLOCATED': 'CPU Allocated',
 'DATA_SIZE': 'Data Size',
 'FUNCTIONAL_USE': 'Functional Use',
 'HAS_REMOTE_ACCESS': 'Has Remote Access',
 'HOST_NAME': 'Host Name',
 'HOST_NUMBER': 'Host Number',
 'HOST_OPERATIONAL_STATUS': 'Host Operational Statu',
 'IS_VIRTUAL': 'Is Virtual',
 'LOGICAL_PARTITION': 'Logical Partition',
 'MEMORY_ALLOCATED': 'Memory Allocated',
 'OPERATING_SYSTEM_SOFTWARE': 'Operating System Software',
 'OPERATIONAL_USE': 'Operational Use',
 'PHYSICAL_PARTITION': 'Physical Partition',
 'SERVER_NAME': 'Server Name',
 'SERVER_NUMBER': 'Server Number',
 'SERVER_OPERATIONAL_STATUS': 'Server Operational Status',
 'ServerHostID': 'ServerHostID',
 'UTILIZATION_PERCENTAGE': 'Utilization Percentage',
 'VM_IP_ADDRESS': 'VM IP Address',
 'VM_NAME': 'VM Name'}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.