A quick help on python dict


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers A quick help on python dict
# 1  
Old 03-12-2019
A quick help on python dict

Hi Team,
I'm new to python and working on a project.
I have an API call which returns a dict(got the dict.values() and converted to list) as shown below:

Code:
dict_values([OffsetAndMetadata(offset=66, metadata=''), OffsetAndMetadata(offset=107, metadata=''), OffsetAndMetadata(offset=189, metadata='')])

Any clue, how can I get only offset values, in deed I need a sum of those. I can write a "shell sed command" inside python and using os.command can get the work done, but looking for a cleaner python solution/hint.
Thanks,
Ravi
This User Gave Thanks to panyam For This Post:
# 2  
Old 03-12-2019
Hi,

Managed to find a solution within python. Can be closed.

Code:
for item in dict.values():
            currentOffset+=int(str(item).partition("offset")[2].partition("metadata")[0].replace('=','').replace(',',''))

thnx
# 3  
Old 03-12-2019
Thanks for sharing and pleased you found by yourself a suitable solution
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies

2. Windows & DOS: Issues & Discussions

How to execute python script on remote with python way..?

Hi all, I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine.. Below is the code I am trying: #!/usr/bin/env python import wmi c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
Discussion started by: onenessboy
1 Replies

3. Shell Programming and Scripting

**python** unable to read the background color in python

I am working on requirement on spreadsheet in python scripting. I have a spreadsheet containing cell values and with background color. I am able to read the value value but unable to get the background color of that particular cell. Actually my requirement is to read the cell value along... (1 Reply)
Discussion started by: giridhar276
1 Replies

4. SuSE

"ssh suse-server 'python -V' > python-version.out" not redirecting

Okay, so I have had this problem on openSUSE, and Debian systems now and I am hoping for a little help. I think it has something to do with Python but I couldn't find a proper Python area here. I am trying to redirect the output of "ssh suse-server 'python -V'" to a file. It seems that no matter... (3 Replies)
Discussion started by: Druonysus
3 Replies

5. Programming

Python: bash-shell-like less functionality in the python shell

Hello, Is there some type of functional way to read things in the Python shell interpreter similar to less or more in the bash (and other) command line shells? Example: >>> import subprocess >>> help(subprocess) ... ... I'm hoping so as I hate scrolling and love how less works with... (0 Replies)
Discussion started by: Narnie
0 Replies

6. Shell Programming and Scripting

grep: can't open /usr/dict/words

Hi All, If I use the "/usr/dict/words" inside the shell script, It is showing the error as, grep: can't open /usr/dict/words How can we resolve it? Thanks & Regards, Raja (2 Replies)
Discussion started by: Rajakct84
2 Replies

7. Shell Programming and Scripting

Need quick help

I have one script that named testing.sh #cat testing.sh #/bin/bash echo "Enter your name:" read name #./testing.sh Enter your name: Sanjay What I need it should take Input in the same prompt(mean to say dun go for next line) like given below. #./testing.sh Enter your name:Sanjay ... (1 Reply)
Discussion started by: SanjayLinux
1 Replies

8. UNIX for Dummies Questions & Answers

i need quick help???...please

hey guys i'm new in this world " unix " i wanna any websites can help me to learn unix or any websites i can download UNIX from it thanks :D (3 Replies)
Discussion started by: M_Hafez
3 Replies
Login or Register to Ask a Question