-4

I have a problem with the fonction. The fonction does not give me the right information

I have this

<function FHD at 0x7f52d72ceaa0>
<function FHD at 0x7f52d72ceaa0>

I look for this information

F1nd6zcHrcaJ6LnVsMMe8Ub_9fnC0gS9dhNFQ_ThInJVDkeJfooSSgxDgjiq6VVWx3OAT912O4q0LcTmJlKroFf63YEsqv2ytLr8q%2BTVlT4%3D-rD4Oo3s9FeXWjFOW2JU2VA%3D%3D

in this files

,"vostf":{"FHD":"33CRwZHs7ZyMW8dTu9j3KjQkvwfmzhA%2BTvYpy5SJna4iyrWKYn_xUzq1srQOQuQlywNeROhRGNB0MC8yqO3Sj7PGb%2BZKTUqBEfZ4f83FNWI%3D-pUS3GCLfkr%2BN5jN%2BKGpxCQ%3D%3D.mp4?audioindex=0","HD":"F1nd6zcHrcaJ6LnVsMMe8Ub_9fnC0gS9dhNFQ_ThInJVDkeJfooSSgxDgjiq6VVWx3OAT912O4q0LcTmJlKroFf63YEsqv2ytLr8q%2BTVlT4%3D-rD4Oo3s9FeXWjFOW2JU2VA%3D%3D.mp4?audioindex=0","MOBILE":"%2BG4zTkYiUg3ADpg4cvqoywZxsXJLvoxEmIvolvRzz6vyYP_B2nTJNGx3teCdKKivxo_PgrDB_o3iFqfBFXY5qrW%2B25l9bXEk2lGRgFp4Ckc0ba6FE95mN%2Brevsj5FoS3-eg4EJWe_bE%2BcjLzc_dSpfw%3D%3D.mp4","SD":"rohgzlYg5krQOwShuYiEgi_LoZHcKk96kr2fPbHBDYmvfWqGnHKdCUuLISlNurkOBfsiAoPS3cXVIFRQ2cTpO3Jq6WklB7eAyUXCas2NfNM%3D-dEaZ85lb5fXeqOD40FOkOg%3D%3D.mp4?audioindex=0"}}

#RECUP QUALITE FHD
import re, os
def FHD(RFHD):
    mykey = open("/home/gaaara/adn/tmp/ajax.json", "r")
    for text in mykey:
        match = re.search('"FHD":"(.+?).mp4', text)
    if match:

        return  match.group(1)
#test
import sys
sys.path.append('files/')
from rez import FHD
oname = FHD
print oname
Zulu
  • 8,765
  • 9
  • 49
  • 56
hideyoshi
  • 37
  • 1
  • 7

1 Answers1

0

That's becasue you are assigning the function itself to the oname variable.you need to call the function and then assign the return value of that function to the variable.

You can do it like this, oname = FHD(). note the parenthesis.

I can see that you are using a function argument named RFHD.but you are not using it inside your function.you gonna have to pass some value to it or else your function call will be failed. something like, oname = FHD('RFHD')

As other have suggested, you can make your life easier by using the built-in json parsing lib.

Take a look at, Parsing values from a JSON file in Python.in your case, you have to use data['vostf']['FHD']

Community
  • 1
  • 1
Himal
  • 1,351
  • 3
  • 13
  • 28
  • mm for the json parsing lib. how to used this i dont no understand the demo in (https://docs.python.org/3/library/json.html) and on mirc Somebody give me this ` json.loads('{"x": 3}')` i dont no understand sorry im a debutent – hideyoshi Jan 20 '15 at 02:58
  • and you have a idea for ini files to get the desired function in a principal script – hideyoshi Jan 20 '15 at 03:06
  • @hideyoshi, I've updated my answer regarding the json parsing. i think it's better to ask a new question regarding the ini file.there is a built-in function for that as well, [ConfigParser](https://docs.python.org/2/library/configparser.html) – Himal Jan 20 '15 at 03:14
  • it works juste I want only the characters ` {"FHD":"33CRwZHs7ZyMW8dTu9j3KjQkvwfmzhA%2BTvYpy5SJna4iyrWKYn_xUzq1srQOQuQlywNeROhRGNB0MC8yqO3Sj7PGb%2BZKTUqBEfZ4f83FNWI%3D-pUS3GCLfkr%2BN5jN%2BKGpxCQ%3D%3D.mp4?audioindex=0` into the " " – hideyoshi Jan 20 '15 at 03:27
  • Sorry, not sure what you meant. you want the all the parts including `{"FHD":` part ? or you meant you don't need all the parts after the file extension ? in that case you can use regex to get the relevant part. first get the 'FHD' value using `data['vostf']['FHD']` and then use your regex to get the filename from that string. – Himal Jan 20 '15 at 03:37
  • for me the regex is the best i have exactly That I need :) – hideyoshi Jan 20 '15 at 03:39
  • @hideyoshi, the JSON specification includes things like escaping rules; no regex can perform unescaping -- it's not a powerful enough language to contain logic of that type -- so any regex-based JSON parser is **necessarily** broken and buggy. Also, your regex is actually broken: You aren't escaping the `.` (which, in regular expressions, mean "match any character") in `.mp4`, meaning that it would also treat `amp4` as the end of a filename. – Charles Duffy Feb 13 '15 at 22:32