Refactoring/Renaming only some variables (of a particular name) in Pycharm (or another IDE)?

Joined
Jul 20, 2023
Messages
56
Reaction score
2
I know this is possible. I've seen "ArjanCodes" on youtube do it. However I do think he uses VScode instead of Pycharm but Im sure it can also be done on Pycharm. Either way. Do you know how to do this on whatever IDE you use? Heres some code to explain what Im talking about.
Python:
class Robot:
    moving = False
    moved = False
    right = False
    left = False
    up = False
    down = False
    x = 0
    y = 0


if Robot.moving:
    if Robot.right:
        Robot.x += 1
        Robot.moving = False
    elif Robot.left:
        Robot.x -= 1
        Robot.moving = False
    if Robot.up:
        Robot.y -= 1
        Robot.moving = False
    elif Robot.down:
        Robot.y += 1
        Robot.moving = False

if not Robot.moving:
    if Robot.right:
        Robot.moving = True
    elif Robot.left:
        Robot.moving = True
    if Robot.up:
        Robot.moving = True
    elif Robot.down:
        Robot.moving = True

Now keep in mind, I know this code doesnt make any sense at all. Its just something I typed up really quick to make an example. So what I want to do is quickly rename all of the "moving" variables in ONLY the bottom if block (if not Robot.moving) to "moved" without changing all of the other "moving" variables in the file. Do you know how this can be done?
 
Joined
Sep 3, 2023
Messages
36
Reaction score
2
With Pluma
1) menu: Search->Replace
2) set fields: Search for & Replace with
3) click on Find button until the first occurrence is highlighted
4) then Replace
 
Joined
Jul 20, 2023
Messages
56
Reaction score
2
Cool thanks. Never heard of pluma but now that I think about it. I think I have seen a search and replace in PyCharm
 
Joined
Sep 3, 2023
Messages
36
Reaction score
2
Its really just rebranded Gedit... Simple generic code editor works for me.
if I needed something more complex I can create an external filter.

Code:
#!/usr/bin/perl

# GEdit.... External Tools,  Input  = Current Selection,  Output = Replace Current Selection

my $cmd = 'zenity --forms --text="Replace Highlighted" --add-entry="Search:" --add-entry="Replace:"';

my ($a) = `$cmd`;
chomp($a);
my ($find, $repl) = split(/\|/, $a);

while(<STDIN>){
    $_ =~ s/$find/$repl/g;
    print $_;
}

Well, that does work all that well, but you get the idea.
 
Joined
Jul 20, 2023
Messages
56
Reaction score
2
Its really just rebranded Gedit... Simple generic code editor works for me.
if I needed something more complex I can create an external filter.

Code:
#!/usr/bin/perl

# GEdit.... External Tools,  Input  = Current Selection,  Output = Replace Current Selection

my $cmd = 'zenity --forms --text="Replace Highlighted" --add-entry="Search:" --add-entry="Replace:"';

my ($a) = `$cmd`;
chomp($a);
my ($find, $repl) = split(/\|/, $a);

while(<STDIN>){
    $_ =~ s/$find/$repl/g;
    print $_;
}

Well, that does work all that well, but you get the idea.
what language is this code written in?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top