To paraphrase Gilbert and Sullivan, a New York policeman’s lot is not a happy one. Cops have been caught up in the city’s political struggles.

Last year, so desperate were some outs to be in, that most of the leading candidates made the NYPD a target. And it’s only grown worse this year.

Not too long ago, the department was being acclaimed for achieving the greatest crime reductions ever registered by an American city. Murder, for example, had fallen 85 percent since 1990.

But now the police are the city’s No. 1 whipping boy.

Police do make mistakes. But so do lawyers, doctors and Wall Street money managers, who perform their work in quiet and safety — whereas a cop carries out his complicated tasks amidst chaos and danger.

So great is the hostility to our men and women in blue that multiple outfits are lined up for a chance to take a swing at them — including the Civilian Complaint Review Board, the new NYPD inspector general, the commissioner of investigation and the new federal monitor, as well as five district attorneys and two US attorney offices.

Even the NYPD’s own commissioner recently stated that at least 1 percent of city cops are “bad apples” whom he intends to weed out. That would come to about 350 dismissals in the next year.

Yet the bad-apple theory is a very weak explanation for police misconduct. Some fine officers have been fired or worse for an honest mistake. On the other hand, certain cops never get into trouble because they manage to dodge unpleasant situations.

Joining officials in the hunt for police scalps is an army of civil-rights lawyers and personal-injury attorneys. Under current city policy, it seems the latter need only file a suit, however baseless, to collect thousands in a quick settlement.

That policy may spare city attorneys work, but can leave a dedicated officer with a black mark on his record.

Then there are the camera bugs, busy trying to film alleged police misconduct. Yet anyone familiar with photography knows photos can be made to lie. A film might have a cop beating a citizen but not show that the incident began with the citizen jumping on the officer’s back.

People can also be trained how to weep and yell for dramatic effect. Maybe the filmmakers them­selves need to be filmed, though I’m sure the New York Civil Liberties Union would sue if the NYPD tried to do it.

Then there are the “witnesses” to alleged police misconduct. Some didn’t observe the incident until after it happened, but will claim to have seen the whole thing. Others neglect to mention that the complainant is their cousin.

In this climate, why would a young person join or remain on the NYPD? The salary is way below that of many suburban departments. The dangers are much greater than in most places.

Topping the list is the fact that a cop subject to a false accusation, or one who makes an honest mistake, can be exonerated and still have his life ruined.

None of which means there’s nothing wrong with the NYPD. But the areas to improve may not be exclusively or even mainly in police conduct.

Notably, some of the current thinking in New York police administration is 20 years behind the times. What worked well in 1994 may be outdated in 2014.

The Broken Windows theory, for example, posits that low-level enforcement is the way to deter serious criminals from taking over a neighborhood.

This may have been true when drug dealers set up operations on every corner and attracted all sorts of troublesome characters. But today it may mainly result only in a roundup of low-level and technical offenders.

In any case, Broken Windows is under a political attack that may render it unsustainable. NYPD brass had better have some other strategies lined up. Activists will be sure to push so-called community policing, but that approach is no substitute for fighting serious crime.

I’ve suggested one strategy: Focus on murderers, rapists and armed robbers via anti-crime drives organized around classic and modern (CSI) police work, which is the wave of the future.

One of two things seems inevitable: Either America’s greatest police department will be reduced to the status of a guard force, with little impact on crime — or the public, alarmed by crime and the terrorist threat, will rally behind our police, make some necessary changes but basically support officers who are doing their jobs.

Thomas A. Reppetto is the former president of the Citizens Crime Commission of New York City and author of “American Police 1845-2012.”