Если у вас много полей в инструкции select, и вы хотите получить последнее значение для всех этих полей с помощью оптимизированного кода:
select * from
(select * from table_name
order by id,rev desc) temp
group by id
Это работает в Python 2.x.
Для Python 3 смотрите здесь:
import urllib.request
with urllib.request.urlopen("http://www.python.org") as url:
s = url.read()
#I'm guessing this would output the html source code?
print(s)
Решение для python3:
from urllib.request import urlopen
url = 'http://www.python.org'
file = urlopen(url)
html = file.read()
print(html)
import urllib.request as ur
filehandler = ur.urlopen ('http://www.google.com')
for line in filehandler:
print(line.strip())
import urllib.request as ur
s = ur.urlopen("http://www.google.com")
sl = s.read()
print(sl)
В Python v3 «urllib.request» является модулем сам по себе, поэтому «urllib» здесь нельзя использовать.
Совместимое с Python 2 + 3 решение:
import sys
if sys.version_info[0] == 3:
from urllib.request import urlopen
else:
# Not Python 3 - today, it is most likely to be Python 2
# But note that this might need an update when Python 4
# might be around one day
from urllib import urlopen
# Your code where you can use urlopen
with urlopen("http://www.python.org") as url:
s = url.read()
print(s)
Для python 3 попробуйте что-то вроде этого:
import urllib.request
urllib.request.urlretrieve('http://crcv.ucf.edu/THUMOS14/UCF101/UCF101/v_YoYo_g19_c02.avi', "video_name.avi")
Он загрузит видео в текущий рабочий каталог
Чтобы получить ' dataX = urllib.urlopen (url) .read () ', работающий в python3 (это было бы правильно для python2) вы должны просто изменить 2 маленькие вещи.
1: сам оператор urllib (добавьте ссылку .request в середине):
dataX = urllib.request.urlopen(url).read()
2: Заявление об импорте, предшествующее ему (измените с «import urlib» на:
import urllib.request
И он должен работать в python3:)