python-3.x

How to remove tabs and newlines with a regex

老子叫甜甜 提交于 2021-02-16 05:09:10
问题 In Python 3.x, the special re sequence '\s' matches Unicode whitespace characters including [ \t\n\r\f\v]. The following piece of code is intended to replace tabs and newlines with a space. import re text = """Hello my friends. How are you doing? I'm fine.""" output = re.sub('\s', ' ', text) print(output) However, the tab is still present in output. Why? 回答1: The problem is(likely) that your tab character is just a bunch of spaces. >>> re.sub(r"\s+", " ", text) "Hello my friends. How are you

How to remove tabs and newlines with a regex

自古美人都是妖i 提交于 2021-02-16 05:08:22
问题 In Python 3.x, the special re sequence '\s' matches Unicode whitespace characters including [ \t\n\r\f\v]. The following piece of code is intended to replace tabs and newlines with a space. import re text = """Hello my friends. How are you doing? I'm fine.""" output = re.sub('\s', ' ', text) print(output) However, the tab is still present in output. Why? 回答1: The problem is(likely) that your tab character is just a bunch of spaces. >>> re.sub(r"\s+", " ", text) "Hello my friends. How are you

How to remove tabs and newlines with a regex

时光毁灭记忆、已成空白 提交于 2021-02-16 05:08:06
问题 In Python 3.x, the special re sequence '\s' matches Unicode whitespace characters including [ \t\n\r\f\v]. The following piece of code is intended to replace tabs and newlines with a space. import re text = """Hello my friends. How are you doing? I'm fine.""" output = re.sub('\s', ' ', text) print(output) However, the tab is still present in output. Why? 回答1: The problem is(likely) that your tab character is just a bunch of spaces. >>> re.sub(r"\s+", " ", text) "Hello my friends. How are you

Using functools.lru_cache on functions with constant but non-hashable objects

核能气质少年 提交于 2021-02-16 04:53:39
问题 Is it possible to use functools.lru_cache for caching a partial function created by functools.partial ? My problem is a function that takes hashable parameters and contant, non-hashable objects such as NumPy arrays. Consider this toy example: import numpy as np from functools import lru_cache, partial def foo(key, array): print('%s:' % key, array) a = np.array([1,2,3]) Since NumPy arrays are not hashable, this will not work: @lru_cache(maxsize=None) def foo(key, array): print('%s:' % key,

Using functools.lru_cache on functions with constant but non-hashable objects

这一生的挚爱 提交于 2021-02-16 04:47:09
问题 Is it possible to use functools.lru_cache for caching a partial function created by functools.partial ? My problem is a function that takes hashable parameters and contant, non-hashable objects such as NumPy arrays. Consider this toy example: import numpy as np from functools import lru_cache, partial def foo(key, array): print('%s:' % key, array) a = np.array([1,2,3]) Since NumPy arrays are not hashable, this will not work: @lru_cache(maxsize=None) def foo(key, array): print('%s:' % key,

Discord bot python: discord.errors.ClientException: ffmpeg was not found

做~自己de王妃 提交于 2021-02-16 03:58:56
问题 I'm trying to make a discord bot that plays music in a voice channel. It connects to the voice channel, but doesn't play anything. It also gives an error in the console. I'm on Windows and I'm using the discord.py rewrite. My code: import discord, random, datetime, asyncio, nacl, ffmpeg TOKEN = 'What token' client = discord.Client() @client.event async def on_message(message): if message.content.lower() == '$play': if message.content.lower() == '$play': channel = client.get_channel

Discord bot python: discord.errors.ClientException: ffmpeg was not found

守給你的承諾、 提交于 2021-02-16 03:54:34
问题 I'm trying to make a discord bot that plays music in a voice channel. It connects to the voice channel, but doesn't play anything. It also gives an error in the console. I'm on Windows and I'm using the discord.py rewrite. My code: import discord, random, datetime, asyncio, nacl, ffmpeg TOKEN = 'What token' client = discord.Client() @client.event async def on_message(message): if message.content.lower() == '$play': if message.content.lower() == '$play': channel = client.get_channel

Discord bot python: discord.errors.ClientException: ffmpeg was not found

馋奶兔 提交于 2021-02-16 03:54:15
问题 I'm trying to make a discord bot that plays music in a voice channel. It connects to the voice channel, but doesn't play anything. It also gives an error in the console. I'm on Windows and I'm using the discord.py rewrite. My code: import discord, random, datetime, asyncio, nacl, ffmpeg TOKEN = 'What token' client = discord.Client() @client.event async def on_message(message): if message.content.lower() == '$play': if message.content.lower() == '$play': channel = client.get_channel

Using modules imported from another import

て烟熏妆下的殇ゞ 提交于 2021-02-15 11:49:57
问题 I'm cleaning up a project that was refactored into smaller .py files. I noticed that a lot of modules are being imported again and again in various files. Some statements are in files that import another which has the same import statement used by the importing file. For example: main.py import alt print (os.getcwd()) alt.py import os The print(os.getcwd()) throws a NameError: name 'os' is not defined . Shouldn't os be part of sys.modules when the import statement is executed in alt.py? Is it

Reading value from HTML page - nseindia

妖精的绣舞 提交于 2021-02-15 07:52:27
问题 I want to read "Open", "High" and "Close" value of NIFTY 50 from the below web page. https://www1.nseindia.com/live_market/dynaContent/live_watch/live_index_watch.htm The below code was working before. Looks like there is some change in the webpage, I am not able to read the values as I am getting below error. nifty_50_row = table.find_all('tr')[2] # get first row of prices AttributeError: 'NoneType' object has no attribute 'find_all' Need your help to fix this issue. My code is as below: url