Phython2019. 5. 21. 12:34

 

글로벌 변수를 사용할려면  global을 메소드안에서 선언해 줘야 한다.

x = 10

 

def foo():

 global x

 x += 1

 print x

 

foo()

https://eli.thegreenplace.net/2011/05/15/understanding-unboundlocalerror-in-python

'Phython' 카테고리의 다른 글

beautifulsoup에서 링크만 빼는법  (0) 2019.05.28
시놀리지에서 vpn client 사용하는 방법  (0) 2019.05.28
파이썬에서 텔레그램 메세지 에코  (0) 2019.05.21
파이썬 simple json 파싱  (0) 2019.05.17
파이썬 web request  (0) 2019.05.17
Posted by 동동(이재동)
Phython2019. 5. 21. 12:01

from telegram.ext import Updater

from telegram.ext import CommandHandler

from telegram.ext import MessageHandler, Filters

 

 

def start(bot, update):

# Your bot will send this message when users first talk to it, or when they use the /start command

bot.sendMessage(chat_id=update.message.chat_id,

text="Hi. Send me any English text and I'll summarize it for you.")

 

def summarize(bot, update):

try:

# Get the text the user sent

text = update.message.text

bot.sendMessage(chat_id=update.message.chat_id,

text=text)

#print(text)

# Run it through the summarizer

except UnicodeEncodeError:

bot.sendMessage(chat_id=update.message.chat_id,

text="Sorry, but I can't summarise your text.")

 

updater = Updater(token=my_token)

dp = updater.dispatcher

 

summarize_handler = MessageHandler(Filters.text, summarize)

start_handler = CommandHandler('start', start)

 

dp.add_handler(summarize_handler)

dp.add_handler(start_handler)

 

dp.bot.sendMessage('사람 id',text="himan")

 

updater.start_polling(timeout=3,clean=True)

updater.idle()

 

Commandhander를 앞에 /나 @에 반응한다.

 

참고 :  https://blog.psangwoo.com/coding/2018/01/09/python-telegram-bot-3.html

 

Posted by 동동(이재동)
Phython2019. 5. 17. 14:27

import json

 

x = json.loads("json string", object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))

print(x.last_price)

Posted by 동동(이재동)
Phython2019. 5. 17. 14:26

import requests

 

url = 'https://api.bitfinex.com/v1/pubticker/btcusd'

response = requests.get(url)

response.status_code

response.text

 

print(response.text)

 

 

Posted by 동동(이재동)