Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions 11 cpp2python.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@

def is_source(filename):
suffixes = ('.cpp', '.c', '.cxx', '.c++', '.cc', '.h', '.hpp', '.hxx', '.h++')
for s in suffixes:
if filename.endswith(s):
return True
return False
return any(filename.endswith(s) for s in suffixes)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is_source refactored with the following changes:

  • Use any() instead of for loop (use-any)


def process_line(line):

Expand Down Expand Up @@ -306,12 +303,12 @@ def main():
if os.path.isdir(sys.argv[1]):
for root, dirs, files in os.walk(sys.argv[1]):
for file in files:
in_filename = root + '/' + file
in_filename = f'{root}/{file}'
if is_source(in_filename):
out_filename = in_filename + '.py' # not ideal
out_filename = f'{in_filename}.py'
process_file(in_filename, out_filename)
elif os.path.isfile(sys.argv[1]):
process_file(sys.argv[1], sys.argv[1] + '.py')
process_file(sys.argv[1], f'{sys.argv[1]}.py')
Comment on lines -309 to +311

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

This removes the following comments ( why? ):

# not ideal

else:
print('Not a file or directory', sys.argv[1], file=sys.stderr)
sys.exit(-1)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.