Python camelcase to underscore

Python camelcase_to_underscore примеры использования

Python camelcase_to_underscore — 5 примеров найдено. Это лучшие примеры Python кода для dhcpkit.utils.camelcase_to_underscore, полученные из open source проектов. Вы можете ставить оценку каждому примеру, чтобы помочь нам улучшить качество примеров.

def export(self) -> Dict[str, int]: """ Export the counters :return: The counters in a processable format """ out = OrderedDict() out['incoming_packets'] = self.incoming_packets.value out['outgoing_packets'] = self.outgoing_packets.value out['unparsable_packets'] = self.unparsable_packets.value out['handling_errors'] = self.handling_errors.value out['for_other_server'] = self.for_other_server.value out['do_not_respond'] = self.do_not_respond.value out['use_multicast'] = self.use_multicast.value out['messages_in'] = OrderedDict() for message_type, counter in self.messages_in.items(): message_type_name = message_registry[message_type].__name__ message_type_name = camelcase_to_underscore(message_type_name) if message_type_name.endswith('_message'): message_type_name = message_type_name[:-8] out['messages_in'][message_type_name] = counter.value out['messages_out'] = OrderedDict() for message_type, counter in self.messages_out.items(): message_type_name = message_registry[message_type].__name__ message_type_name = camelcase_to_underscore(message_type_name) if message_type_name.endswith('_message'): message_type_name = message_type_name[:-8] out['messages_out'][message_type_name] = counter.value return out
def test_camelcase_to_underscore(self): self.assertEqual(camelcase_to_underscore('CamelCase'), 'camel_case') self.assertEqual(camelcase_to_underscore('CamelCASE'), 'camel_case') self.assertEqual(camelcase_to_underscore('CAMELCase'), 'camel_case') self.assertEqual(camelcase_to_underscore('MyCAMELCase'), 'my_camel_case') self.assertEqual(camelcase_to_underscore('Camel123Case'), 'camel123_case') self.assertEqual(camelcase_to_underscore('CAMEL123Case'), 'camel123_case') self.assertEqual(camelcase_to_underscore('Camel-Case'), 'camel_case') self.assertEqual(camelcase_to_underscore('camel-case'), 'camel_case') self.assertEqual(camelcase_to_underscore('Camel_Case'), 'camel_case') self.assertEqual(camelcase_to_underscore('camel_case'), 'camel_case')
def export(self) -> Dict[str, int]: """ Export the counters :return: The counters in a processable format """ out = OrderedDict() out['incoming_packets'] = self.incoming_packets.value out['outgoing_packets'] = self.outgoing_packets.value out['unparsable_packets'] = self.unparsable_packets.value out['handling_errors'] = self.handling_errors.value out['for_other_server'] = self.for_other_server.value out['do_not_respond'] = self.do_not_respond.value out['use_multicast'] = self.use_multicast.value out['unknown_query_type'] = self.unknown_query_type.value out['malformed_query'] = self.malformed_query.value out['not_allowed'] = self.not_allowed.value out['other_error'] = self.other_error.value out['messages_in'] = OrderedDict() for message_type, counter in self.messages_in.items(): message_type_name = message_registry[message_type].__name__ message_type_name = camelcase_to_underscore(message_type_name) if message_type_name.endswith('_message'): message_type_name = message_type_name[:-8] out['messages_in'][message_type_name] = counter.value out['messages_out'] = OrderedDict() for message_type, counter in self.messages_out.items(): message_type_name = message_registry[message_type].__name__ message_type_name = camelcase_to_underscore(message_type_name) if message_type_name.endswith('_message'): message_type_name = message_type_name[:-8] out['messages_out'][message_type_name] = counter.value return out
def test_camelcase_to_underscore(self): self.assertEqual(camelcase_to_underscore('CamelCase'), 'camel_case') self.assertEqual(camelcase_to_underscore('CamelCASE'), 'camel_case') self.assertEqual(camelcase_to_underscore('CAMELCase'), 'camel_case') self.assertEqual(camelcase_to_underscore('MyCAMELCase'), 'my_camel_case') self.assertEqual(camelcase_to_underscore('Camel123Case'), 'camel123_case') self.assertEqual(camelcase_to_underscore('CAMEL123Case'), 'camel123_case') self.assertEqual(camelcase_to_underscore('Camel-Case'), 'camel_case') self.assertEqual(camelcase_to_underscore('camel-case'), 'camel_case') self.assertEqual(camelcase_to_underscore('Camel_Case'), 'camel_case') self.assertEqual(camelcase_to_underscore('camel_case'), 'camel_case') self.assertEqual(camelcase_to_underscore('SimpleCamelCase'), 'simple_camel_case') self.assertEqual(camelcase_to_underscore('DHCPTest'), 'dhcp_test') self.assertEqual(camelcase_to_underscore('DHCP-Test'), 'dhcp_test') self.assertEqual(camelcase_to_underscore('DHCP--Test'), 'dhcp_test') self.assertEqual(camelcase_to_underscore('DHCP_Test'), 'dhcp_test') self.assertEqual(camelcase_to_underscore('DHCP__Test'), 'dhcp_test') self.assertEqual(camelcase_to_underscore('DHCP-_Test'), 'dhcp_test') self.assertEqual(camelcase_to_underscore('DHCP_-Test'), 'dhcp_test') self.assertEqual(camelcase_to_underscore('DHCPv6Test'), 'dhc_pv6_test') self.assertEqual(camelcase_to_underscore('DHCPV6Test'), 'dhcpv6_test') self.assertEqual(camelcase_to_underscore('DHCPVersion6plusTest'), 'dhcp_version6plus_test')
def test_camelcase_to_underscore(self): self.assertEqual(camelcase_to_underscore('CamelCase'), 'camel_case') self.assertEqual(camelcase_to_underscore('CamelCASE'), 'camel_case') self.assertEqual(camelcase_to_underscore('CAMELCase'), 'camel_case') self.assertEqual(camelcase_to_underscore('MyCAMELCase'), 'my_camel_case') self.assertEqual(camelcase_to_underscore('Camel123Case'), 'camel123_case') self.assertEqual(camelcase_to_underscore('CAMEL123Case'), 'camel123_case') self.assertEqual(camelcase_to_underscore('Camel-Case'), 'camel_case') self.assertEqual(camelcase_to_underscore('camel-case'), 'camel_case') self.assertEqual(camelcase_to_underscore('Camel_Case'), 'camel_case') self.assertEqual(camelcase_to_underscore('camel_case'), 'camel_case') self.assertEqual(camelcase_to_underscore('SimpleCamelCase'), 'simple_camel_case') self.assertEqual(camelcase_to_underscore('DHCPTest'), 'dhcp_test') self.assertEqual(camelcase_to_underscore('DHCP-Test'), 'dhcp_test') self.assertEqual(camelcase_to_underscore('DHCP--Test'), 'dhcp_test') self.assertEqual(camelcase_to_underscore('DHCP_Test'), 'dhcp_test') self.assertEqual(camelcase_to_underscore('DHCP__Test'), 'dhcp_test') self.assertEqual(camelcase_to_underscore('DHCP-_Test'), 'dhcp_test') self.assertEqual(camelcase_to_underscore('DHCP_-Test'), 'dhcp_test') self.assertEqual(camelcase_to_underscore('DHCPv6Test'), 'dhc_pv6_test') self.assertEqual(camelcase_to_underscore('DHCPV6Test'), 'dhcpv6_test') self.assertEqual(camelcase_to_underscore('DHCPVersion6plusTest'), 'dhcp_version6plus_test')

Источник

Читайте также:  Python openpyxl открыть файл

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A lightweight tool to convert all CamelCase instances in a file to underscore naming conventions

kmjungersen/CamelCase_to_underscore

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

This tool will help you convert files that use CamelCase conventions to _underscoring!

Running the program is simple:

If you want to convert a single phrase (or a number of phrases for that matter), run the program as is and it will prompt you for a phrase to convert.

If you have a file (or many files!) to convert, place them in the ‘to be converted’ directory and then run the program. It will detect the files that are there and then read them, convert them, and place the converted file in the ‘converted’ directory!

IMPORTANT NOTE: MAKE SURE TO COPY YOUR FILES to the ‘to_be_converted’ directory, because after running this program, IT WILL DELETE THEM! Ye have been warned!

About

A lightweight tool to convert all CamelCase instances in a file to underscore naming conventions

Источник

camelcase to underscore

Here are the examples of how to camelcase to underscore in python. These are taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

def camelCase_to_underscore(str): """ >>> camelCase_to_underscore('camelcase') 'camelcase' >>> camelCase_to_underscore('camelCase') 'camel_case' >>> camelCase_to_underscore('camelCamelCase') 'camel_camel_case' """ return re.sub(pattern, sub, str).lower() 
def camelcase_to_underscore(str): # http://djangosnippets.org/snippets/585/ return re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', '_\\1', str).lower().strip('_') 
def camelcase_to_underscore(string): """Convert string from ``CamelCase`` to ``under_score``.""" return re.sub('((?<=[a-z0-9])[A-Z]|(? 
def camelcase_to_underscore(string): """Convert string from ``CamelCase`` to ``under_score``.""" return (re.sub('((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))', r'_\1', string) .lower()) 
  • camel to underscore
  • test camel to underscore
  • test convert to underscore
  • a64 load store
  • a solve b test factory
  • accept tos
  • acceptoptional
  • access group initiator add
  • access group initiator delete
  • access token
  • accumulator
  • action button
  • action button confirm
  • action button present
  • action restore
  • action to dict
  • action to str
  • actiongoto

Источник

Оцените статью