Python의 문자열에서 인쇄할 수 없는 문자 제거
질문:
Perl에서는, 인쇄할 수 없는 문자는 정규식 s/[^[:print:]]//g를 사용하여 제거할 수 있습니다. 그러나 Python에서는 [:print:] 클래스가 지원되지 않습니다. ASCII와 유니코드 문자를 모두 처리하는 Python에서 유사한 기능을 어떻게 얻을 수 있습니까?
답변:
인쇄 가능성 감지에 대한 Python의 제한으로 인해 자체 문자를 구성할 수 있습니다. unicodedata 모듈을 사용하는 클래스입니다.
<code class="python">import unicodedata, re, itertools, sys # Generate a list of all characters all_chars = (chr(i) for i in range(sys.maxunicode)) # Category of control characters categories = {'Cc'} control_chars = ''.join(c for c in all_chars if unicodedata.category(c) in categories) # Escape the control characters for regular expression matching control_char_re = re.compile('[%s]' % re.escape(control_chars)) # Function to remove control characters from a string def remove_control_chars(s): return control_char_re.sub('', s)</code>
Python 2의 경우:
<code class="python">import unicodedata, re, sys # Generate a list of all characters all_chars = (unichr(i) for i in xrange(sys.maxunicode)) # Category of control characters categories = {'Cc'} control_chars = ''.join(c for c in all_chars if unicodedata.category(c) in categories) # Escape the control characters for regular expression matching control_char_re = re.compile('[%s]' % re.escape(control_chars)) # Function to remove control characters from a string def remove_control_chars(s): return control_char_re.sub('', s)</code>
확장 옵션:
의 경우 보다 포괄적인 제거를 위해서는 추가 범주를 포함할 수 있지만 성능에 영향을 미칠 수 있습니다.
문자 범주 및 개수:
- 참조(컨트롤): 65
- Cf(형식): 161
- Cs(대리): 2048
- Co(개인 사용): 137468
- Cn(할당되지 않음): 836601
위 내용은 Python 문자열에서 인쇄할 수 없는 문자를 제거하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

toAppendElementStoapyThonList, usetHeappend () MethodForsingleElements, extend () formultipleements, andinsert () forspecificpositions.1) useappend () foraddingOneElementatateend.2) usextend () toaddmultipleementsefficially

To TeCreateAtheThonList, usequareBrackets [] andseparateItemswithCommas.1) ListSaredynamicandCanholdMixedDatAtatypes.2) useappend (), remove () 및 SlicingFormAnipulation.3) listlisteforences;) ORSL

금융, 과학 연구, 의료 및 AI 분야에서 수치 데이터를 효율적으로 저장하고 처리하는 것이 중요합니다. 1) 금융에서 메모리 매핑 파일과 Numpy 라이브러리를 사용하면 데이터 처리 속도가 크게 향상 될 수 있습니다. 2) 과학 연구 분야에서 HDF5 파일은 데이터 저장 및 검색에 최적화됩니다. 3) 의료에서 인덱싱 및 파티셔닝과 같은 데이터베이스 최적화 기술은 데이터 쿼리 성능을 향상시킵니다. 4) AI에서 데이터 샤딩 및 분산 교육은 모델 교육을 가속화합니다. 올바른 도구와 기술을 선택하고 스토리지 및 처리 속도 간의 트레이드 오프를 측정함으로써 시스템 성능 및 확장 성을 크게 향상시킬 수 있습니다.

PythonArraysareCreatedusingThearrayModule, Notbuilt-inlikelists.1) importThearrayModule.2) SpecifyTyPeCode (예 : 'forIntegers.3) 초기에 초기화 성과의 공동체 정보가없는 사람들이 플렉스리스트.

Shebang 라인 외에도 Python 통역사를 지정하는 방법에는 여러 가지가 있습니다. 1. 명령 줄에서 직접 Python 명령을 사용하십시오. 2. 배치 파일 또는 쉘 스크립트를 사용하십시오. 3. Make 또는 Cmake와 같은 빌드 도구를 사용하십시오. 4. Invoke와 같은 작업 러너를 사용하십시오. 각 방법에는 장점과 단점이 있으며 프로젝트의 요구에 맞는 방법을 선택하는 것이 중요합니다.

forhandlinglargedatasetsinpython, usenumpyarraysforbetterperformance.1) numpyarraysarememory-effic andfasterfornumericaloperations.2) leveragevectorization foredtimecomplexity.4) managemoryusage withorfications data

inpython, listsusedyammoryAllocation과 함께 할당하고, whilempyarraysallocatefixedMemory.1) listsAllocatemememorythanneedInitiality.

Inpython, youcansspecthedatatypeyfelemeremodelerernspant.1) usenpynernrump.1) usenpynerp.dloatp.ploatm64, 포모 선례 전분자.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

드림위버 CS6
시각적 웹 개발 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.