小编Ger*_*rts的帖子

python colorama 打印所有颜色

我是Python的新手,我遇到了colorama。作为一个测试项目,我想打印出 colorama 中所有可用的颜色。

from colorama import Fore
from colorama import init as colorama_init

colorama_init(autoreset=True)

colors = [x for x in dir(Fore) if x[0] != "_"]
for color  in colors:
    print(color + f"{color}")
Run Code Online (Sandbox Code Playgroud)

当然,这会输出全黑输出,如下所示:

BLACKBLACK
BLUEBLUE
CYANCYAN
...
Run Code Online (Sandbox Code Playgroud)

因为 Dir(Fore) 只是给了我Fore.BLUE, Fore.GREEN, ...的字符串表示形式

有没有办法访问所有前景色属性,以便它们实际工作,如下所示:

print(Fore.BLUE + "Blue")
Run Code Online (Sandbox Code Playgroud)

或者换句话说,这可能更好地表达我的问题。

我想写这个:

print(Fore.BLACK + 'BLACK')
print(Fore.BLUE + 'BLUE')
print(Fore.CYAN + 'CYAN')
print(Fore.GREEN + 'GREEN')
print(Fore.LIGHTBLACK_EX + 'LIGHTBLACK_EX')
print(Fore.LIGHTBLUE_EX + 'LIGHTBLUE_EX')
print(Fore.LIGHTCYAN_EX + 'LIGHTCYAN_EX')
print(Fore.LIGHTGREEN_EX + 'LIGHTGREEN_EX')
print(Fore.LIGHTMAGENTA_EX + 'LIGHTMAGENTA_EX')
print(Fore.LIGHTRED_EX + …
Run Code Online (Sandbox Code Playgroud)

python properties colorama

9
推荐指数
1
解决办法
3万
查看次数

使用 http 代理的 aiohttp https 请求失败

我正在构建一个测试项目来学习 asyncio。我正在构建一个通过代理服务器获取多个页面的程序。

它对于 http 页面工作正常,但对于 https 页面则失败。当我使用常规请求库时,我也可以使用 https 页面,但不能使用 asyncio。

我隔离了损坏的代码:

import aiohttp
import asyncio

async def fetch(url):
    async with aiohttp.ClientSession() as session:
        async with session.get(url, proxy="http://192.168.0.2:9001") as response:
            print(await response.text())

loop = asyncio.get_event_loop()
loop.run_until_complete(fetch("https://google.com")) #http websites do work
Run Code Online (Sandbox Code Playgroud)

错误:

Traceback (most recent call last):
  File "C:\Users\GG\AppData\Local\Programs\Python\Python38-32\lib\site-packages\aiohttp\connector.py", line 936, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "C:\Users\GG\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 1050, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "C:\Users\GG\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 1080, in _create_connection_transport
    await waiter
  File …
Run Code Online (Sandbox Code Playgroud)

python proxy python-asyncio aiohttp

3
推荐指数
1
解决办法
3498
查看次数

Powershell Call Base Class Function From Overidden Function

I want to make a call to the parent function from its overidden function, i isolated my problem in the following code:

class SomeClass{
  [type]GetType(){
    write-host 'hooked'
    return $BaseClass.GetType() # how do i call the BaseClass GetType function??
  }
}
SomeClass::new().GetType()
Run Code Online (Sandbox Code Playgroud)

i am expecting an output like this:

hooked
IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     SomeClass                                System.Object
Run Code Online (Sandbox Code Playgroud)

oop powershell overriding base-class

2
推荐指数
1
解决办法
986
查看次数