在试图组合两个API的整个上下文中,我需要“合并”两个函数结果,以便使所有内容都井井有条。
def descr():
return 88
def name():
return 'Account',descr()
当我打印name()时,得到此信息(“帐户”,88)。这种格式的问题是我以后无法在脚本中使用此结果。
这是整个脚本:
import requests
import json
url = "https://proxy6.net/api/xxx/getproxy"
def descr():
return 88
def name():
return 'Account',descr()
querystring = {"descr":descr()}
headers = {
'Cache-Control': "no-cache",
'Postman-Token': "xxxx"
}
response = requests.request("GET", url, headers=headers, params=querystring)
data = response.json()
for value in data['list'].values():
host = value['host']
port = value['port']
url = "https://api.multiloginapp.com/v1/profile/create"
querystring = {"token":"xxx"}
payloadobj = {
"generateZeroFingerprintsData": True,
"name": name(),
"OS": "MacOS",
"platform": "MacIntel",
"browserType": "mimic",
"proxyHost": host,
"proxyPort": port,
"proxyIpValidation": False,
"proxyType": "socks5",
"maskFonts": True,
"disablePlugins": True,
"disableWebrtcPlugin": True,
"disableFlashPlugin": True,
"canvasDefType": "noise",
"hardwareConcurrency": 2,
"langHdr": "en-US,en;q=0.8",
"timeZone": "US/Eastern",
"audio": {
"noise": True
},
"geolocation": {
"permitType": "block"
},
"mediaDevices": {
"audioInputs": 1,
"audioOutputs": 1,
"videoInputs": 1
},
"webgl": {
"noise": True
},
"webRtc": {
"type": "block"
},
"shared": False
}
payload = json.dumps(payloadobj)
headers = {
'Content-Type': "application/json",
'Cache-Control': "no-cache",
'Postman-Token': "xxx"
}
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
print(response.text)
我希望上面的JSON查询中的名称值是name + descr的结果,但不适用于该返回格式。
答案 0 :(得分:1)
看起来像您需要的。
def descr():
return 88
def name():
return '{} {}'.format('Account', descr())
print(name())
输出:
Account 88
答案 1 :(得分:1)
09-06 16:11:21.716 3821-3821/? I/art: Late-enabling -Xcheck:jni
09-06 16:11:21.738 3821-3827/? E/art: Failed sending reply to debugger: Broken pipe
09-06 16:11:21.739 3821-3827/? I/art: Debugger is no longer active
Starting a blocking GC Instrumentation
09-06 16:11:21.850 3821-3821/? W/System: ClassLoader referenced unknown path: /data/app/com.example.hosseinry.tour-1/lib/x86
09-06 16:11:21.865 3821-3821/? I/InstantRun: starting instant run server: is main process
09-06 16:11:21.931 3821-3821/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
09-06 16:11:21.947 3821-3835/? D/libEGL: loaded /system/lib/egl/libEGL_adreno.so
09-06 16:11:21.974 3821-3835/? D/libEGL: loaded /system/lib/egl/libGLESv1_CM_adreno.so
09-06 16:11:21.985 3821-3835/? D/libEGL: loaded /system/lib/egl/libGLESv2_adreno.so
09-06 16:11:22.063 3821-3837/? I/OpenGLRenderer: Initialized EGL, version 1.4
09-06 16:11:22.063 3821-3837/? D/OpenGLRenderer: Swap behavior 1
09-06 16:11:22.106 3821-3837/? W/EGL_emulation: eglSurfaceAttrib not implemented 3093 12436
09-06 16:11:22.106 3821-3837/? W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb707f2c0, error=EGL_SUCCESS
09-06 16:11:22.123 3821-3821/? W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
09-06 16:12:13.209 3821-3821/com.example.hosseinry.tour I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
09-06 16:12:13.213 3821-3821/com.example.hosseinry.tour I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
09-06 16:12:13.215 3821-3821/com.example.hosseinry.tour I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
09-06 16:12:13.217 3821-3821/com.example.hosseinry.tour I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
09-06 16:12:13.319 3821-3837/com.example.hosseinry.tour W/EGL_emulation: eglSurfaceAttrib not implemented 3093 12436
09-06 16:12:13.319 3821-3837/com.example.hosseinry.tour W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb70042a0, error=EGL_SUCCESS
09-06 16:12:13.400 3821-3837/com.example.hosseinry.tour D/OpenGLRenderer: endAllActiveAnimators on 0xb149d480 (RippleDrawable) with handle 0x9d2244a0
返回一个元组对象而不是字符串。要返回一个字符串,您可以将其更改为:
name()
答案 2 :(得分:0)
如果您使用的是python3.6或更高版本,则可以:
def descr():
return 88
def name():
return f"Account {descr()}"