TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #65 · 8 апр.

Небольшой трик с регулярными выражениями который редко вижу в чужом коде. Допустим, вам нужно распарсить простой текст и вытащить оттуда пары имя+телефон. Вернуть всё это надо в виде списка словарей. Возьмем очень простой пример текста. >>> text = ''' >>> Alex:8999123456 >>> Mike:+799987654 >>> Oleg:+344456789 >>> ''' Соответственно, для выделения нужных элементов будем использовать группы. Получится такой паттерн: (\w+):([\d+]+) Как мы будем формировать словарь из найденных групп? >>> import re >>> results = [] >>> for match in re.finditer(r"(\w+):([\d+]+)", text): >>> results.append({ >>> "name": match.group(1), >>> "phone": match.group(2) >>> }) >>> print(results) [{'name': 'Alex', 'phone': '8999123456'}, ...] Можно немного сократить запись используя zip >>> results = [] >>> for match in re.finditer(r"(\w+):([\d+]+)", text): >>> results.append(dict(zip(['name', 'phone'], match.groups()))) Но есть способ лучше! Это именованные группы в regex. Можно в паттерне указать имя группы и результат сразу забрать в виде словаря. >>> for match in re.finditer(r"(?P<name>\w+):(?P<phone>[\d+]+)", text): >>> results.append(match.groupdict()) То есть всё что я сделал, это добавил в начале группы (внутри сбокочек) такую запись: (?P<group-name>...) Теперь найденная группа имеет имя и можно обратиться к ней как к элементу списка >>> name = match['name'] Либо забрать сразу весь словарь методом groupdict() >>> match.groupdict() #tricks#regex

Резултати

Пронајдени 7 слични објави

Пребарај: #socket

当前筛选 #socket清除筛选
djangoproject

@djangoproject · Post #327 · 30.04.2017 г., 01:28

https://www.tutorialspoint.com/python/python_networking.htm Python provides two levels of access to network services. At a low level, you can access the basic #socket support in the underlying operating system, which allows you to implement #clients and #servers for both connection-oriented and connectionless protocols.

djangoproject

@djangoproject · Post #439 · 13.09.2017 г., 03:57

Evented Django part one: Socket.IO and gevent #Socket.IO was developed with a #Node.JS server implementation, but work is being done to add server implementations to a variety of languages. Two such servers exist for Python, tornadio and #gevent-socketio. I'm a big fan of gevent, so I will use gevent-socketio, but tornadio looks well-written and very promising. http://codysoyland.com/2011/feb/6/evented-django-part-one-socketio-and-gevent/

djangoproject

@djangoproject · Post #457 · 04.10.2017 г., 03:01

https://pythonspot.com/en/python-network-sockets-programming-tutorial/ Python network sockets programming tutorial In this tutorial you will learn about in #network programming. You will learn about the #client-#server model that is in use for the World Wide Web, E-mail and many other applications. #socket

djangoproject

@djangoproject · Post #456 · 04.10.2017 г., 02:57

http://www.techbeamers.com/python-tutorial-essentials-of-python-socket-programming/ Essentials of Python #Socket Programming You Should Know Python offers two types of #API libraries that we can use for socket programming. At the low-level, Python utilizes the “socket” library to implement #client and #server#modules for both #connectionless and #connection-oriented #network protocols. Whereas, at the higher-level, You can use libraries like #ftplib and #httplib to interact with application-level network protocols like #FTP and #HTTP.

djangoproject

@djangoproject · Post #298 · 17.04.2017 г., 07:42

#AI#Artificial_Intelligence #aiohttp #API #AWS #asyncio #audio #automated_testing #automation #atexit #BeeWare #button #client #concurrency #cron #Coroutine #data_analysis #data_mining #data_processing #database #Deep_Learning #Debian #decorator #dispatch #django #dropdownbox #Docker #event #Firefox #form #freeze #functool #Generator #GeoDjango #Google #GPU #Gym #learn #Image_processing #intelligence #input #IOT #lambda #lists #machine_learning #Magenta #map #Metaprogramming #Micro_services #mind #monitoring #MongoDB #Mozilla #Multipart #multi_touch_apps #multiprocessing #Nodes #NoSQL #numeric_computation #numerical #NumPy #OAuth #object_serialization #OCR #overloading #package #parallel #pipeline #protocols #PostGIS #pyAudioAnalysis #PyInstaller #PySide #PyTorch #pytest #python #Pyvideo_archives #Qt #Redis #random #request #REST #satellite #scrapy #scikit_learn #SciPy #searching #submit #selectbox #Selenium #serialization #server #session #socket #sound #task #TensorFlow #text_boxes #text #test #telegram #Thread #transport #tuples #Universe #Unix #urllib #upload #Web

djangoproject

@djangoproject · Post #425 · 28.08.2017 г., 03:37

#AI#Artificial_Intelligence #aiohttp #AngularJS #API #AWS #asyncio #audio #automated_testing #automation #atexit #BeeWare #button #client #concurrency #Coroutine #cron #curl #data_analysis #data_mining #data_processing #database #Deep_Learning #Debian #decorator #dict #dispatch #django #django_cms #dropdownbox #Docker #event #Firefox #form #Generator #GeoDjango #git #Google #GPU #Gym #learn #Image_processing #intelligence #input #IOT #lambda #learn #lists #machine_learning #Magenta #map #Metaprogramming #Micro_services #mind #monitoring #MongoDB #Mozilla #Multipart #multi_touch_apps #multiprocessing #Nodes #NoSQL #numeric_computation #numerical #NumPy #OAuth #object_serialization #OCR #overloading #package #parallel #pipeline #protocols #PostGIS #pyAudioAnalysis #pycon #Pyflakes #PyInstaller #PySide #PyTorch #pytest #python #Pyvideo_archives #Qt #React #Redis #random #request #REST #satellite #scrapy #scikit_learn #SciPy #searching #submit #selectbox #Selenium #serialization #server #socket #task #telegram #TensorFlow #test #text_boxes #text #tuples #unicode #Universe #Unix #urllib #upload #Web

djangoproject

@djangoproject · Post #513 · 30.11.2017 г., 22:00

#AI#Artificial_Intelligence #AJAX #aiohttp #Anaconda #AngularJS #API #Atom #AWS #asyncio (#Asynchronous) #audio #automated_testing #automation #atexit #BeeWare #Big_Data #bitcoin #blockchain #Bluemix #Brython #button #Celery #client #class #classmethod #concurrency #Coroutine #cron #CSS #curl #data_analysis #data_mining #data_processing #database #Deep_Learning#deep_learning #Debian #decorator #deploy #dict #dispatch #django #django_cms #Django_REST_Framework #dropdownbox #Docker #event #Firefox #Flask #form #functions #Generator #GeoDjango #git #Google #GPU #GUI #Gym #host #HTML #httplib #learn #Image_processing #intelligence #input #Instagram #IOT #iPython #Jupyter #lambda #learn #License #Linux #lists #machine_learning #Magenta #map #Matplotlib #Metaprogramming #Micro_services #Micropython #mind #monitoring #MongoDB #modules #Mozilla #Multipart #multi_touch_apps #multiprocessing #Nodes #NoSQL #numeric_computation #numerical #NumPy #network #neural_network #OAuth #object_serialization #OCR #overloading #package #parallel #pipeline #protocols #PostGIS #pyAudioAnalysis #pycon #Pyflakes #PyInstaller #PyPI #PyQt #PySide #PyTorch #pytest #python #Pyvideo_archives #Qt #Raspberry_Pi #React #Redis #random #request #Regular_Expressions (#re) #REST #RSS #satellite #scikit_learn #SciPy #scrapy #searching #selectbox #Selenium #serialization #server #sessions #single_responsibility_principle #socket #Spark #str #submit #task #telegram #template #TensorFlow #test #text_boxes #text #tuples #unicode #Universe #Unix #unit_test #urllib #upload #uWSGI #Web #WSGI