GVKun编程网logo

Python-sort()和reverse()函数不起作用(python中sort和reverse)

20

此处将为大家介绍关于Python-sort的详细内容,并且为您解答有关和reverse的相关问题,此外,我们还将为您介绍关于Click()函数在python/Selenium中不起作用、curl_in

此处将为大家介绍关于Python-sort的详细内容,并且为您解答有关和reverse的相关问题,此外,我们还将为您介绍关于Click()函数在python / Selenium中不起作用、curl_init()函数不起作用、eval()和JSON.parse()解析数据、geolocator.reverse()TypeError:reverse()接受2个位置参数,但在pyspark中给出了3个的有用信息。

本文目录一览:

Python-sort()和reverse()函数不起作用(python中sort和reverse)

Python-sort()和reverse()函数不起作用(python中sort和reverse)

我试图根据我正在阅读的教程测试python中的列表如何工作。当我尝试使用list.sort()or时list.reverse(),口译员给了我None

请让我知道如何从这两种方法获得结果:

a = [66.25, 333, 333, 1, 1234.5]print(a.sort())print(a.reverse())

答案1

小编典典

简单的升序排序非常简单,请调用sorted()函数。它返回一个新的排序列表:

>>> sorted([66.25, 333, 333, 1, 1234.5])[1, 66.25, 333, 333, 1234.5]

sorted()接受带有布尔值的反向参数。

>>> sorted([66.25, 333, 333, 1, 1234.5], reverse=True)[1234.5, 333, 333, 66.25, 1]

答案2

小编典典

.sort()和.reverse()更改列表中的位置,并返回None参见可变序列文件:

sort()reverse()排序或反向的大名单时,方法的空间经济性修改到位名单。为了提醒你,它们是副作用,它们不会返回已排序或反向的列表。

而是这样做:

a.sort()print(a)a.reverse()print(a)

或使用sorted()和reversed()功能。

print(sorted(a))               # just sortedprint(list(reversed(a)))       # just reversedprint(a[::-1])                 # reversing by using a negative slice stepprint(sorted(a, reverse=True)) # sorted *and* reversed

这些方法返回一个新列表,并保持原始输入列表不变。

演示,原位排序和反向:

>>> a = [66.25, 333, 333, 1, 1234.5]>>> a.sort()>>> print(a)[1, 66.25, 333, 333, 1234.5]>>> a.reverse()>>> print(a)[1234.5, 333, 333, 66.25, 1]

并创建新的排序和反向列表:

>>> a = [66.25, 333, 333, 1, 1234.5]>>> print(sorted(a))[1, 66.25, 333, 333, 1234.5]>>> print(list(reversed(a)))[1234.5, 1, 333, 333, 66.25]>>> print(a[::-1])[1234.5, 1, 333, 333, 66.25]>>> print(sorted(a, reverse=True))[1234.5, 333, 333, 66.25, 1]>>> a  # input list is untouched[66.25, 333, 333, 1, 1234.5]

Click()函数在python / Selenium中不起作用

Click()函数在python / Selenium中不起作用

请参阅我对您发布的问题的评论。最后,我确实找到了您的按钮,但是如果不使用JavaScript,就无法点击它:

from selenium import webdriver

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
try:
    driver.implicitly_wait(6) # wait up to 6 seconds to find an element
    driver.get("https://www.nike.com/ch/fr/launch?s=upcoming")
    
    loginBtns = driver.find_elements_by_xpath("/html/body/div[2]/div/div/div[1]/div/header/div[1]/section/div/ul/li[1]/button")
    if loginBtns:
        #loginBtns[0].click()
        driver.execute_script('arguments[0].click()',loginBtns[0])
    else:
        print('Could not find login button.')
finally:
    driver.quit()

curl_init()函数不起作用

curl_init()函数不起作用

嗨,我尝试在POST请求中尝试PHPPost请求,认为这可能对我有用,下面给出了我的代码

$sub_req_url = "http://localhost/index1.php";

$ch = curl_init($sub_req_url);
$encoded = '';

// include GET as well as POST variables; your needs may vary.
foreach($_GET as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';
}

foreach($_POST as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';
}

// chop off last ampersand
$encoded = substr($encoded,strlen($encoded)-1);

curl_setopt($ch,CURLOPT_POSTFIELDS,$encoded);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_POST,1);
curl_exec($ch);
curl_close($ch);

形成index.php文件,而index2.php是同一目录中的另一个文件,当我打开页面时,我的error.log文件中出现以下错误

[Sat Dec 18 15:24:53 2010] [error] [client ::1] PHP Fatal error:  Call to undefined function curl_init() in /var/www/testing1/index.php on line 5

我想要做的是我有一个发送发帖请求的预订表格,然后我想处理发帖值并再次将发帖请求发送到贝宝

eval()和JSON.parse()解析数据

eval()和JSON.parse()解析数据

JSON.parse()的用法比较单一,只能常规的将字符串JSON化,而eval()的用法很强大,除了常规的将字符串JSON化,还可以进行运算,拼接,处理表达式

1.如果data是字符串,使用eval("("+data+")")可以将其转换为json对象,和JSON.parse的功能一样。
   如果data是json对象,使用eval("("+data+")")会报错,正如你描述的错误。eval一个json对象, 没有什么作用,这个时候不需要使用eval方法,直接用data即可。

2.为什么eval要添加括号呢?

首先eval是可以处理js表达式的

eval("x=10;y=20;document.write(x*y)");
document.write( eval("2+2"));
document.write( eval(x+17));

//得到结果
200427;

添加括号原因eval本身的问题。 由于json是以{}的方式来开始以及结束的,在JS中,它会被当成一个语句块来处理,而eval不能处理语句块,可以处理表达式,所以加上括号强制性的将它转换成一种表达式。

加上圆括号的目的是迫使eval函数在处理JavaScript代码的时候强制将括号内的表达式(expression)转化为对象,而不是作为语句(statement)来执行。举一个例子,例如对象字面量{},如若不加外层的括号,那么eval会将大括号识别为JavaScript代码块的开始和结束标记,那么{}将会被认为是执行了一句空语句。

console.log(eval("{}"); // undefined 
console.log(eval("({})");// object[Object] 

geolocator.reverse()TypeError:reverse()接受2个位置参数,但在pyspark中给出了3个

geolocator.reverse()TypeError:reverse()接受2个位置参数,但在pyspark中给出了3个

我也尝试过:

    def direccion_func(coordenadas):
           dir = geolocator.reverse(coordenadas)
           return dir.address
    
        direccion = pandas_udf(direccion_func,returnType = StringType())
    
       paradasRuta1DF = 

paradasRuta1DF.withColumn('Direccion',direccion_func(F.col("LatLong")))

并显示错误:TypeError:无法从Column

创建Point实例 ,

我认为您收到此错误的原因是 reverse 函数应将包含给定坐标的元组或列表作为参数。

我们今天的关于Python-sort和reverse的分享就到这里,谢谢您的阅读,如果想了解更多关于Click()函数在python / Selenium中不起作用、curl_init()函数不起作用、eval()和JSON.parse()解析数据、geolocator.reverse()TypeError:reverse()接受2个位置参数,但在pyspark中给出了3个的相关信息,可以在本站进行搜索。

本文标签: